Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Function program
Index -> Programming, C -> C Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
stef_ios




PostPosted: Sat Mar 08, 2008 2:45 pm   Post subject: Function program

Hey! So i'm writing a program that does the following:

Consider the building of an airport with the runway being built on landfill. The contractor has two dump trucks, one with a capacity of 8 tons and the other with a capacity of 12 tons. The contractor uses the trucks to haul fill from a remote site to the airport location. The operating cost per trip for the 8 and 12 ton trucks is $14.57 and $16.26, respectively. One truck cannot make more than 60 percent of the total trips. Prompt the user to enter the total number of tons. Display the number of trips required for each truck and the total cost. Use a modular design for this program.

So I've done just a basic program for starters, but the calculations I don't think are working properly, can someone tell me why?

code:

#include<stdio.h>

int
main(void)

{
        int tons, tonstruck1, tonstruck2, tripstruck1, tripstruck2;
        double total_cost;
       
        tons=0;
        tonstruck1=0;
        tonstruck2=0;
        tripstruck1=0;
        tripstruck2=0;
        total_cost=0;

        /* Truck 1 is the 12 ton truck, truck 2 is the 8 ton truck */

        printf("Please enter the total number of tons: ");
        scanf("%d", &tons);

        printf("\n\n");

        tripstruck1 = tons * 0.60 / 12;
        tonstruck1 = tripstruck1 * 12 ;
        tonstruck2 = tons - tonstruck1;
        tripstruck2 = tonstruck2 / 8;
        total_cost = tripstruck1*16.26 + tripstruck2*14.57;

        printf("-------------------------------------------------------------------------------\n");
        printf(" Number of Tons | Total Cost | Trips by 8 Ton Truck | Trips by 12 Ton Truck    \n");
        printf("-------------------------------------------------------------------------------");
        printf("         %d     |    %5.2lf  |         %d            |          %d             \n", tons, total_cost,
                        tripstruck2, tripstruck1);
        printf("-------------------------------------------------------------------------------");


        return(0);

}

Sponsor
Sponsor
Sponsor
sponsor
A.J




PostPosted: Sat Mar 08, 2008 3:05 pm   Post subject: Re: Function program

remember that the trucks go up and down
so you have to multiply the cost by 2 (since I think you forgot to add that to your program).

Make sure that u also minimize the cost by making truck 1 take x% and truck 2 take y%.
When truck 1 always takes 60%, it doesn't necessarily minimize the total cost.

Try writing equations, and if u need more help, I'll be glad to help u.

But overall, it looks nice Smile
stef_ios




PostPosted: Sat Mar 08, 2008 6:17 pm   Post subject: Re: Function program

Thanks! I'll work on it some more! Very Happy
A.J




PostPosted: Sat Mar 08, 2008 9:00 pm   Post subject: Re: Function program

your welcome Very Happy
md




PostPosted: Sat Mar 08, 2008 10:22 pm   Post subject: RE:Function program

Unless of course the cost per round trip is $14 and $16 (or whatever numbers were given).

Also, though your problem statement says that is must be modular your code is pretty hard coded.
A.J




PostPosted: Mon Mar 10, 2008 5:55 pm   Post subject: Re: Function program

so, how are you finding it stef_ios!
do you need help with this optimization, or are you done with this question?
A.J
Display posts from previous:   
   Index -> Programming, C -> C Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: