Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

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.

• This is what I have so far.... I know it might be totally off..

Code:
```#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");

}```

• 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.

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

• ## Users who have thanked oracleguy for this post:

Treymer0 (09-15-2011)

• I am using C, my teacher didnt require a book because he said everything is on the web. Ill start on the inputs.

• 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);

• 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)

• ## Users who have thanked oracleguy for this post:

Treymer0 (09-15-2011)

• so printf declares what I want to do, and scanf stores it?

• like this?:

scanf ("%f",&miles);

scanf ("%f",&gasoline);

scanf ("%f",&milespergallon);

scanf ("%f",&parkingfees);

scanf ("%f",&tolls);

• 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.

• ## Users who have thanked oracleguy for this post:

Treymer0 (09-15-2011)

• 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");

}

• 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?

• ## Users who have thanked oracleguy for this post:

Treymer0 (09-15-2011)

• 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);

• ive tried to run it and it says error..

• That is much better. What is the error that you are getting?

• 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");

}

•
Page 1 of 2 12 Last

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•