# Thread: Help with program homework!!!

1. ## Help with program homework!!!

I have to write a program that determines the miles per gallon for
3 tanks of gasoline. The program prompts you to enter the number of gallons used and number of miles driven for each of the 3 tankfuls of gas. The program will then calculate and display the miles per gallon obtained for each tankful. I can't figure out how to write the statement to calculate this. Below is what I have. If anyone can help, or give me some idea on where I am wrong, i would appreciate it.
Code:
```/* Variable Declarations */

int x, result, miles_per_gallon;
float gallons_used, miles_driven;

/* Greeting*/

printf("Welcome to the Acme Mileage Calculator Program\n\n");

printf ("Enter the number of gallons used:");
scanf ("%.1f",&gallons_used);

printf("Enter the number of miles driven:");
scanf("%.1f",&miles_driven);

for (x = galons_used / miles_driven;)

result = x;

printf("Miles per gallon for this tank is %i\N",x,result);
[edited for code tags by ygfperson]```
I know the result is wrong....does anyone have an example similar that uses division?
Thank you.

2. Have you even tried to compile? It'll point you to all the errors and you should be able to debug it.

>> for (x = galons_used / miles_driven
This is an infinite loop. You misspelled galons_used. Variable x is type int, therefore you results will be truncated (you'll lose decimal values).

Having both variables x and result is redundant.

>> printf("Miles per gallon for this tank is %i\N",x,result);
You printed out 1 parameter here but passed in 2.

3. I am only allowed to use 1 variable and 2 to 3 floats. How do I create the formula only using one variable? I picked x to = the miles per gallon and tried to work backwards...am I way off? Thank you for your help

4. Your for loop is way off...

for(int x=0;x<100;x++)
{

cout<<x<<endl; //Outputting x
}

That's just the format of the for loop... not the way you have it.

Also, you want to change the math to

(miles_driven/gallons_used)

5. Fix the obvious errors first. Your loop tells me you don't even know the basics. Why not start there first?