How do I fix identifier and primary expression errors?

Discussion in 'C Programming' started by shy402, Feb 28, 2015.

  1. shy402

    shy402

    Joined:
    Feb 28, 2015
    Messages:
    1
    Likes Received:
    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;
    ^
     
    shy402, Feb 28, 2015
    #1
    1. Advertisements

  2. shy402

    old-student

    Joined:
    Mar 22, 2015
    Messages:
    7
    Likes Received:
    2
    Location:
    SE Washington
    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.
     
    old-student, Mar 23, 2015
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. Mark Goldin

    Errors, errors, errors

    Mark Goldin, Jan 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,330
    Mark Goldin
    Jan 17, 2004
  2. Xah Lee
    Replies:
    22
    Views:
    1,619
    Tim Roberts
    Mar 21, 2006
  3. Xah Lee
    Replies:
    23
    Views:
    1,517
    Tim Roberts
    Mar 21, 2006
  4. Kobu
    Replies:
    7
    Views:
    813
  5. aarthi28@gmail.com
    Replies:
    2
    Views:
    2,337
    chris_doran@postmaster.co.uk
    Feb 26, 2007
  6. babakandme@yahoo.com
    Replies:
    2
    Views:
    1,316
    Owen Jacobson
    Dec 11, 2007
  7. S_K
    Replies:
    0
    Views:
    1,002
  8. Xah Lee
    Replies:
    21
    Views:
    1,249
    Tim Roberts
    Mar 21, 2006
Loading...