I am working on a program , the do while part is not functioning .Can anyone please tell me what is wrong with the following code.
the error it shows is
syntax error : 'return'
do
{
cout << "Enter M to caluculate Miles Per gal , D for distance traveled , G for Gals used and Q to quit the program ";
cin >> ch ;
cout << ch << endl ;
switch (ch)
{
case 'm':
case 'M':
MilesperGal();
break ;
case 'd':
case 'D':
mileage();
break ;
case 'g':
case 'G':
fuelUsed ();
break;
default:
return 0;
} while (ch!='q' || ch!='Q');
}
return 0;
In the future:
- Please use [code][/code] tags
- Please tell what line the error occurs on
Your problem is because the 'while' is at the end of the switch{} and not at the end of the do{}. Therefore it errors saying "return is unexpected" because it expects a while statement after the do{} closes, and there isn't one.
99.9% of the time, "Unresolved External Symbol" means that you're calling a function that doesn't have a body.
Here, it's complaining about "_main", which is the entry point for the program. In order to have a C++ program, you need to have a function called "main" -- this is where your program starts.
1 2 3 4 5 6 7 8
int main()
{
// your program executing code here
// put program code here
return 0;
}
Note that "program code" does not include stuff like #include statements or other functions. main() should've been one of the first things talked about in whatever class/book/tutorial you're using =x