How do I fix identifier and primary expression errors?

Joined
Feb 28, 2015
Messages
1
Reaction score
0
Code:
#include <iostream>
using namespace std;
int main () {
string queens;
string password = queens;
string int = 1;
string guess;
cout << "Guess the password or enter 1 to exit! \n";
cin >> guess;
while (( guess != password )) && (( guess != (int)) {
cout << "Try again or enter 1 to exit. \n";
} if ((guess == password )) {
cout << "Congratz! That is the correct password! \n";
} else if ( guess == (int)) {
return 0;
}
return 0;
}
Errors:
CS111ShyanBhairoHW3.cpp: In function ‘int main()’:
CS111ShyanBhairoHW3.cpp:6:13: error: expected unqualified-id before ‘=’ token
string int = 1;
^
CS111ShyanBhairoHW3.cpp:10:36: error: expected identifier before ‘(’ token
while (( guess != password )) && (( guess != (int)) {
^
CS111ShyanBhairoHW3.cpp:10:36: error: expected ‘;’ before ‘(’ token
CS111ShyanBhairoHW3.cpp:14:24: error: expected primary-expression before ‘int’
} else if ( guess == (int)) {
^
CS111ShyanBhairoHW3.cpp:14:24: error: expected ‘)’ before ‘int’
CS111ShyanBhairoHW3.cpp:17:1: error: expected ‘)’ before ‘return’
return 0;
^
 
Joined
Mar 22, 2015
Messages
7
Reaction score
2
Shy,
your second error points to line 6 space 13 in main: string int =1;
both 'string' and 'int' are reserved words so the error is telling you that you don't have a variable name for string or int.

The next error points out that your parentheses don't match.

Most of the errors appear to be syntax related, so look it over good and the re post your fixed code using "[" 'code' "]" before it and "["'/code'"]" after it.

That should make it easier to figure out what you are doing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,053
Messages
2,570,431
Members
47,075
Latest member
TysonV438

Latest Threads

Top