problem in the program

I have asked alot of question about this program but still not able to sovle it
can any one tell me how to fix this proplem
i will be thankful


#include<iostream>
using namespace std;


double MilesperGal(double F,double m)
{
double M;
M = m/F;
return M;
};
double mileage(double F,double M)
{
double m;
m=F*M;
return m;
}
double fuelUsed (double M,double MPG)
{
double f;
f=M/MPG;
return f;
}
int main()

{
double FuelUsed;
double Mileage;
double MilesPerGal;

char x ;

cout<<"Enter M to caluculate mileage , D for distance traveled ,G for Gal per miles and Q to quit the program ";
cin>>x ;

do {


if ( x=='m' || x=='M')




cout << "enter the fuel used";
cin>>FuelUsed;
cout<<"enter mileage ";
cin>>Mileage;
cout<<MilesperGal(FuelUsed,Mileage);

else if ( x=='d' || x=='D')


cout << "enter the fuel used";
cin>>FuelUsed;
cout<<"enter MPG ";
cin>>MilesPerGal;
cout <<mileage(FuelUsed,MilesPerGal );
else if (x=='g; || x=='D')

cout << "enter the Mileage used";
cin>>Mileage;
cout<<"enter mileage ";
cin>>MilesPerGal;
cout<<fuelUsed (Mileage,MilesPerGal) ;
}
while (x!='q' || x!='Q')




return 0;
}
Last edited on
masiht, honestly, you've asked a _lot_ of very basic questions over the past few weeks/months. In each case you seem to just keep asking questions until someone posts the answer for you. Given the very basic syntax errors you have in the above code, I'm not sure how much effort you are putting into these assignments, because it seems that you are not really learning much.

Don't misunderstand me; it's not that I don't want to help you. I just think you are doing yourself a disservice by letting us do your homework for you. You are paying a lot of money for your college education and you are investing a lot of time in it too.

Now without even running your code through a compiler I see at least 4 syntactical errors that you should be able to diagnose and fix yourself.

Beyond that, stdout (to which cout writes) is line buffered, so doing something like:

cout << "enter the fuel used";
cin >> FuelUsed;

is not going to show you the text before the program expects you to input the fuel used. You need either to print a newline (endl) or flush the stream explicitly (cout << flush;).

Your program also is an infinite loop because you ask the user to exter M,D,G, or Q and then read the user's input before the do{} loop, but you never ask them a second time, which means the while() condition at the bottom will never be false unless they entered Q the first time, and since x never changes, you'll always enter the same if/else block each time.
Can you please fix this program problems ?
Your response FAILS.
Ohohohow. That has to be the best reply I've seen in this forum.
Or, at least, the best by someone with over 100 posts.
jsmith
Please post your current code. I expect that you've corrected all the syntax errors and that the code at least compiles cleanly. I also expect that you fixed the cout buffering issue I mentioned above.
I did everything Ok but it is still saying that illegal else doesn't match with if.
if you want more than one statement in an if block or an else if block or an else block you need braces.
Topic archived. No new replies allowed.