And another addition: all C keywords (and function names from the standard function library) are written in lowercase.
As C is case-sensitive, <strong>Return 0;</strong> isn't valid, and has to be written like <strong>return 0;</strong> instead.
As already told you bytuse, you have to put a return statement inside a function's body, to fix your code, you take a look at tuse's post, and you move the return statement inside your main function.
(Take into account that you have to write it in lowercase!)
tux4life
Nearly a Posting Maven
2,350 posts since Feb 2009
Reputation Points: 2,134
Solved Threads: 243
BTW, not only missing semicolons in your code, also wrong formatting specifiers:
You declared the following variables as of type integer:
int fuel, mpg, miles, fuelr; , but in yourscanfs, you tell the scanf function that you expect a floating point number, not an integer.
If your intention was getting a floating point number from the user, then you should declare your variables as of type float or double, otherwise you leave them all of type integer, and you change the formatting specifiers in all the scanfs from %f to %d.
Also you have to change: printf(fuelr * fuel); to printf(<strong>"%f",</strong>fuelr * fuel); (if you declare your variables to be of a floating point type), or printf(<strong>"%d",</strong>fuelr * fuel); (if you declare your variables to be of typeinteger).
Remember: The printf and scanf functions always need to know exactly what type of data they have to deal with.
tux4life
Nearly a Posting Maven
2,350 posts since Feb 2009
Reputation Points: 2,134
Solved Threads: 243
Well, I guess you haven't seen my previous post, because you were writing your post at the same moment as I was writing it, so I would suggest you to check my previous post out, and fix the errors in your program.
tux4life
Nearly a Posting Maven
2,350 posts since Feb 2009
Reputation Points: 2,134
Solved Threads: 243
Well, you forgot to add semicolons there:
printf("Trip Summary.%d")<strong>;</strong> <strong>// <--</strong>
printf("Fuel Required.%d", miles / mpg);
printf("Enter Total amount of fuel required.%d")<strong>;</strong> <strong>// <--</strong>
BTW, things like this in your code: printf("Enter Price of Fuel per gallon.<strong>%d</strong>"); will result inundefined behaviour, because for each format specifier you add, you also have to pass a corresponding value to printf.
My suggestion to fix the undefined behaviour: remove every %d format specifier which is at the end of the string you print using printf.
tux4life
Nearly a Posting Maven
2,350 posts since Feb 2009
Reputation Points: 2,134
Solved Threads: 243
your last few lines, where you're presumably calculating and printing the "fuel required" doesnt make any sense.
youre supposed to calculate the fuel required, not prompt the user to enter the fuel required.
fuel required is calculated by "total miles / miles per gallon" ... you can print it like this: printf("Amount of Fuel Required: %f gallons\n", miles/mpg);
and the Total Cost of Fuel Required is equal to the "total fuel required * cost per gallon", so you should now be able to figure this out.
jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179
Add a do-while loop around the main portions of the code. At the end of the loop simply ask a question. Input the answer and the while conditional can exit the loop or not.But, you should read this series about scanf() first.
And you might as well read this , too.
WaltP
Posting Sage w/ dash of thyme
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944