1magus Posted September 17, 2008 Share Posted September 17, 2008 //Tyler Weiss #include <stdio.h> //Fuel SCAN PROGRAM void main(void) { float distance, gallons, MPG; printf("Enter distance followed by space than gallons used. \n"); scanf("%f %f", &distance, &gallons); MPG = "%f / %f", &distance, &gallons; printf("Fuel Effiency is: %f\n", MPG); } My teacher told us to make a program that calculates the fuel effeicny in Gallons and Liters and I know this is wrong lol but I can't get this to work and I do not have the liters area yet any help anybody? Quote Link to comment Share on other sites More sharing options...
+karri Posted September 18, 2008 Share Posted September 18, 2008 MPG = "%f / %f", &distance, &gallons; The MPG = garbage line is a bit strange. Something along a formula from your math lessons might be what you are looking for. MPG = distance / gallons; But the rest of the program looks OK to me. -- Karri Quote Link to comment Share on other sites More sharing options...
Shawn Jefferson Posted September 29, 2008 Share Posted September 29, 2008 (edited) MPG = "%f / %f", &distance, &gallons; Like Karri said, you have tried to use the syntax of the scanf function to do math. C = A / B; // division C = A % B; // mod C = A * B; // multiplication C = A + B; // addition C = A - B; // subtraction that's the basic math syntax in C... you could probably ask your teacher for help, that's what he's there for! Oh, I've always considered it good programming style to put in a "return;" even when the function doesn't return anything. Is that not taught today, or am I just plain wrong on that? Edited September 29, 2008 by Shawn Jefferson Quote Link to comment Share on other sites More sharing options...
+selgus Posted January 10, 2009 Share Posted January 10, 2009 Oh, I've always considered it good programming style to put in a "return;" even when the function doesn't return anything. Is that not taught today, or am I just plain wrong on that? I don't know I would consider that good programming style. That is a redundant statement, which doesn't aide readability IMO, so I would leave it out. --Selgus Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.