...

View Full Version : Need help bad!



Treymer0
09-14-2011, 11:09 PM
DISCLAIMER: I AM NOT ASKING ANYONE TO WRITE MY PROGRAM (just help).

So, I am new to C programming and I dont understand it very well... My teacher wants me to write a code for the following:

(Car-Pool Savings Calculator) Research several car-pooling websites. Create an application
that calculates your daily driving cost, so that you can estimate how much money could be saved by
car pooling, which also has other advantages such as reducing carbon emissions and reducing traffic
congestion. The application should input the following information and display the userís cost per
day of driving to work:
a) Total miles driven per day.
b) Cost per gallon of gasoline.
c) Average miles per gallon.
d) Parking fees per day.
e) Tolls per day.
total = tolls + parkFee + (miles/mpg)*gasCost
Output should like this:
The total miles driven per day: 100
The cost per gallon of gasoline: $ 3.00
The average miles per gallon: 19 mph
The parking fees per day: $ 3.00
The tolls per day: $4.00
Your daily cost of driving to work is $ 22.79

I need help bad, I dont want you to write my code, I want to learn how to do it on my own. If anyone is able to help me complete my assignment that would be awsome. Or give me links, examples, anything to work with to help me understand this language... I am using Microsoft visual c++ 2010 express btw. Thanks everyone in advance for the help.

Treymer0
09-14-2011, 11:10 PM
This is what I have so far.... I know it might be totally off..



#include <stdio.h>

#include <iostream>



void main()

{
float tolls;

float parkFee;

float miles;

float mpg;

float gasCost



printf ("The total miles driven per day: ");

scanf ("%f",&miles);




total = tolls + parkFee + (miles/mpg)*gasCost;

printf("The total miles driven per day: %0.5f \n",radius);

printf("The cost per gallon of gasoline: %0.5f \n",diameter);

printf("The average miles per gallon: %0.5f \n",area);

printf("The parking fees per day: %0.5f \n",circumference);

printf("The tolls per day: %0.5f \n",circumference);

printf("Your daily cost of driving to work is: %0.5f \n",circumference);


system("PAUSE");

}

oracleguy
09-14-2011, 11:12 PM
Well start with writing the code to ask the user for those 5 different inputs and storing them in variables. Are you writing this in C or C++? Look in the book that came with your course on reading input from the console.

Ok I see your code now, that is a start now you need ask for the remaining four variables and read them in.

Treymer0
09-14-2011, 11:13 PM
I am using C, my teacher didnt require a book because he said everything is on the web. Ill start on the inputs.

Treymer0
09-14-2011, 11:18 PM
ok, so I added this:


printf ("Total miles driven per day: ");

printf ("Cost per gallon of gasoline: ");

printf ("Average miles per gallon: ");

printf ("Parking fees per day: ");

printf ("Tolls per day: ");


scanf ("%f",&miles);

oracleguy
09-14-2011, 11:20 PM
Ok, now you need to call scanf after the printf to take the user input and store into the correct variable. I see you already declared the variables you'll need except for total. (You'll want to fix that)

Treymer0
09-14-2011, 11:26 PM
so printf declares what I want to do, and scanf stores it?

Treymer0
09-14-2011, 11:34 PM
like this?:


scanf ("%f",&miles);

scanf ("%f",&gasoline);

scanf ("%f",&milespergallon);

scanf ("%f",&parkingfees);

scanf ("%f",&tolls);

oracleguy
09-15-2011, 01:00 AM
printf just prints whatever text you want to the console. That text is what the user reads.

By declaring I meant declaring variables. When you write float tolls; you are declaring a variable with a name of tolls of type float.

Your scanfs look correct, put it all together and you almost have it.

Treymer0
09-15-2011, 04:07 AM
OK, this is what I have now:


/* Architect: Tyler Reymer
Date: 09/14/2011
Project: Daily cost driving to work.
*/



#include <stdio.h>

#include <iostream>



void main()

{
// float

float miles;

float gasCost;

float mpg;

float parkFees;

float tolls;

// Printf in

printf ("Total miles driven per day: ");

printf ("Cost per gallon of gasoline: ");

printf ("Average miles per gallon: ");

printf ("Parking fees per day: ");

printf ("Tolls per day: ");

// Scanf

scanf ("%f",&miles);

scanf ("%f",&gasCost);

scanf ("%f",&mpg);

scanf ("%f",&parkFees);

scanf ("%f",&tolls);



// Calculation


total = tolls + parkFee + (miles/mpg)*gasCost;


// printf out

printf("The total miles driven per day: %0.5f \n",miles);

printf("The cost per gallon of gasoline: %0.5f \n",gasCost);

printf("The average miles per gallon: %0.5f \n",mpg);

printf("The parking fees per day: %0.5f \n",parkFees);

printf("The tolls per day: %0.5f \n",tolls);

printf("Your daily cost of driving to work is: %0.5f \n",total);

// pause screen

system("PAUSE");

}

oracleguy
09-15-2011, 04:12 AM
Close but think about this, shouldn't each scanf be right after the question it is accepting input for? Wouldn't that more sense? Fix that and you still need to fix your total variable. I take it you haven't tried compiling it yet?

Treymer0
09-15-2011, 04:20 AM
ok, so this is what I did... closer? lol im starting to understand this a lot better though.


// float

float miles;

float gasCost;

float mpg;

float parkFees;

float tolls;

float total;

// Printf in

printf ("Total miles driven per day: ")

scanf ("%f",&miles);

printf ("Cost per gallon of gasoline: ");

scanf ("%f",&gasCost);

printf ("Average miles per gallon: ");

scanf ("%f",&mpg);

printf ("Parking fees per day: ");

scanf ("%f",&parkFees);

printf ("Tolls per day: ");

scanf ("%f",&tolls);

or should i do it more like this for the printf/scanf:

printf ("Total miles driven per day: ") scanf ("%f",&miles);

Treymer0
09-15-2011, 04:24 AM
ive tried to run it and it says error..

oracleguy
09-15-2011, 05:06 AM
That is much better. What is the error that you are getting?

Treymer0
09-15-2011, 05:50 AM
its just saying there are build errors when i debug it...

heres the final code (do you see anything wrong?):


/* Architect: Tyler Reymer
Date: 09/14/2011
Project: Daily cost driving to work.
*/



#include <stdio.h>

#include <iostream>



void main()

{
// float;


float miles;


float gasCost;


float mpg;


float parkFees;


float tolls;


float total;


// printf in;


printf("Total miles driven per day: ");

scanf("%f",&miles);

printf("Cost per gallon of gasoline: ");

scanf("%f",&gasCost);

printf("Average miles per gallon: ");

scanf("%f",&mpg);

printf("Parking fees per day: ");

scanf("%f",&parkFees);

printf("Tolls per day: ");

scanf("%f",&tolls);




// calculation;


total = tolls + parkFee + (miles/mpg)*gasCost;


// printf out;

printf("The total miles driven per day: %0.5f \n",miles);

printf("The cost per gallon of gasoline: %0.5f \n",gasCost);

printf("The average miles per gallon: %0.5f \n",mpg);

printf("The parking fees per day: %0.5f \n",parkFees);

printf("The tolls per day: %0.5f \n",tolls);

printf("Your daily cost of driving to work is: %0.5f \n",total);

// pause screen;

system("PAUSE");

}

oracleguy
09-16-2011, 09:31 PM
Sorry for the delay in getting back to this thread. Did you get your program all done?

clary413
02-24-2012, 12:04 AM
(Car-Pool Savings Calculator) Research several car-pooling websites. Create an application that calculates your daily driving cost, so that you can estimate how much money could be saved by car pooling, which also has other advantages such as reducing carbon emissions and reducing traffic congestion. The application should input the following information and display the user's cost per day of driving to work:

Total miles driven per day.
Cost per gallon of gasoline.
Average miles per gallon.
Parking fees per day.
Tolls per day.


// Program to calculate car pool savings.
#include <iostream>

using namespace std;

int main()
{
double miles, gas, average, parking, tolls, total;
cout<<"Enter miles driven per day"<<endl;
cin>> miles;
cout<<"Enter cost of gas"<<endl;
cin>> gas;
cout<<"Enter average driven per day"<<endl;
cin>> average;
cout<<"Enter parking fees"<<endl;
cin>> parking;
cout<<"Enter tolls per day"<<endl;
cin>> tolls;


total=(miles*gas)/average+(parking+tolls);
cout<<"total"<<endl;


return 0;
}

Is there ANYTHING wrong?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum