Odd to have cin.ignore in the loop structure, I would of placed that before return 0, but I suppose it depends on the OP and how he/she wants to implement the program
Odd to have cin.ignore in the loop structure, I would of placed that before return 0, but I suppose it depends on the OP and how he/she wants to implement the program
Double Helix STL
Try running your program from the commandline, and see if the window still blinks.
OK I get an error on the line that says do.Code:#inclide <iostream using namespace std; int main() { int a; int ( a == 159753 ) do { cout<< "Password:"; cin>> a; cin.ignore(); } while ( a != 159753 ) cout<< "Incorrect, try again.\n"; } else if ( a == 159753 ) cout<< "Correct, please proceed."; }
What is wrong there?
do while loops have to end with a semicolon:
And your if needs an opening bracket.Code:} while ( a != 159753 );
If you fix your indentation, the problem should be obvious.
Edit: Never mind, there's more than one problem and the first one is before the broken indentation starts (though that doesn't help).
Edit: Actually, I see two errors on the very first line. I'm surprised the compiler got as far as it did.
Last edited by robatino; 03-26-2007 at 05:34 PM.
"expected `;' before "do""
That is the error I get on the do line.
what does that mean exactly?
It means that the compiler expected a semi-colon before the word "do" on that line. That means that the previous line has confused the compiler. It may be something small, like adding a semi-colon, or it may be something more complicated, like accidentally typing int when you meant if.
On line 19 (the one with else if) gets these errorsCode:#include <iostream> using namespace std; int main() { int a; int ( a == 159753 ); do{ cout<< "Password:"; cin>> a; cin.ignore(); } while ( a != 159753 ); cout<< "Incorrect, try again.\n"; } else if ( a == 159753 ) { cout<< "Correct, please proceed."; }
expected unqualified-id before "else"
expected `,' or `;' before "else"
How can I fix it?
Can someone patch up the program abocve for me?
There seems to be a few things wrong with it.
For starters, the line
doesn't make sense. You don't seem to need it anyway, so get rid of it. After that, fix your indentation as I suggested earlier, and you will uncover other mistakes yourself.Code:int ( a == 159753 );
It says
expected primary-expresion before "eleS"
expected `;' before "else"
[line 23]expected `}' at end of input (times 2)
What do all those mean?
You program won't exit the loop until a == 159753 so there is no point in checking what it is. You can't have an else if statement unless you have an if statement preceeding it. You don't want the '}' right after the while ( a != 159753 ); And main should return 0; although technically you don't need it. And just remove int ( a == 159753);.
Don't quote me on that... ...seriously
I changed it to thisCode:#include <iostream> using namespace std; int main() { int a; cout<< "Password:"; cin>> a; cin.ignore(); if ( a != 159753 ); { cout<< "Incorrect, try again.\n"; } else { cout<< "Correct, please proceed."; } cin.get(); }
It got rid of all the errors except
expected primary-expresion before "eleS"
expected `;' before "else"
what can i do to fix it?
Remove the semicolon at the end.Code:if ( a != 159753 );
Don't quote me on that... ...seriously