C++ Problem..

Started by
7 comments, last by jcdenton999 20 years, 12 months ago
Can someone please tell me what is wrong with this program. I can''t find any errors. The compiler has said: Line 34 - parse error before `<'' and Line 48 - parse error at end of input #include <iostream> using namespace std; int main() { char c; while(true) { cout <<"MAIN MENU: " <)"; cin >> c; if (c==''q'') { break; if (c==''l'') { cout <<"LEFT MENU: " <> c; if (c==''a'') { cout << "You chose ''a''!!!" <> c; if (c==''c'') { cout << "You chose ''c''!"; <<endl; continue; } if (c==''d'') { cout <<"You chose ''d''" <<endl; continue; } else { cout <<"You didn''t choose c or d!" <<endl; } cout << "Quitting menu....." <<endl; } thanks for any help...
Advertisement
Whoa, that program is full of errors. < cout, < continue, < }, etc. are all illegal. You seem to be missing braces (or have too many), in several places. You're also missing some semicolons.

Maybe the forum screwed up the code. Try putting it between [ source ] and [ /source ] tags (without the spaces).

[edited by - micepick on April 19, 2003 4:25:12 PM]
you''re using the cout function incorrrectly in several places:

Change

cout <<"MAIN MENU: " )";

and similar, to

cout <<"MAIN MENU: " << "Enter -- (l:left) (r:right) (q:quit =>)";

and change

cout <<"You didn''t choose c or d!" <}

to

cout <<"You didn''t choose c or d!";

I''ll be honest with you, and please don''t take offense. You will need to take some tutorials on C++ before attempting to use the language for game programming.

Good luck.

Sorry...I dunno what the hell happened with the code. I''ll try to put it between source tags but I dunno if that will work.
All the

  #include <iostream>using namespace std;int main(){char c;while(true){cout <<"MAIN MENU: " <<endl;cout <<"Enter -- (l:left) (r:right) (q:quit =>)";cin >> c;if (c==''q''){break;if (c==''l''){cout <<"LEFT MENU: " <<endl;cout <<"Select a or b: ";cin >> c;if (c==''a''){cout << "You chose ''a''!!!" <<endl;continue;}if (c==''b'') {cout << "You chose ''b''!" <<endl;continue;}}if (c==''r'') {cout <<"RIGHT MENU: " <<endl;cout <<"Select c or d: ";cin >> c;if (c==''c''){cout << "You chose ''c''!"; <<endl;continue;}if (c==''d''){cout <<"You chose ''d''" <<endl;continue;}else{cout <<"You didn''t choose c or d!" <<endl;}cout << "Quitting menu....." <<endl;}  


Anyway---any problems with this.
Do some indentation. The way it looks to me, your braces are badly mismatched (you''re missing some closing ones). Of course, that may be intentional but it''s hard to tell what you''re doing without any indentaion and so many nested ifs.
It''s a slow day, and I need practice doing the error thing without using my compiler anyways Lesse...

Dunno whether it will compile as an error, but some whitespace between the #include the using commands would be good...

Indenting would also be nice, although I''ve seen forums screw that over before, so I won''t nail ya to the wall over it. (This time )

Missing a closing brace on the first if. (Just after the break) (Presumably the cause of your second error)

Logic error...

You''ll only get the Quitting Menu message if you select something from the right menu.

I get those on my first pass through, if I could be bothered copy-pasting to a compiler window, might be able to find more. I would like to reiterate that layout is very important to good, readable code. Get in the habit early, and you can sit on a high-horse and bitch about others not doing it too. It makes you feel surprisingly superior :D

Press to test... *click* Release to detonate...
Press to test... *click* Release to detonate...
jcdenton999 of Deus Ex,

Try the switch statement. It''s much neater and more readable.
quote:Original post by Faradhi
Dunno whether it will compile as an error, but some whitespace between the #include the using commands would be good...

That''s a bug in the Gamedev forum code... It fails to insert a newline after a compiler directive even though the OP put it there...

Kippesoep

  cout << "You chose ''c''!"; <<endl;  


There''s your problem, most likely.
-YoshiXGXCX ''99

This topic is closed to new replies.

Advertisement