rock, paper, scissors game

This is a discussion on rock, paper, scissors game within the C++ Programming forums, part of the General Programming Boards category; Trying to make a rock, paper, scissors game but I keep on getting these error messages: error C2059: syntax error ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    18

    rock, paper, scissors game

    Trying to make a rock, paper, scissors game but I keep on getting these error messages:
    error C2059: syntax error : 'else'
    error C2143: syntax error : missing ';' before '{'
    error C2447: '{' : missing function header (old-style formal list?)



    Here is my code:

    Code:
    #include <iostream>
    #include <ctime>
    using namespace std;
    
    void you_win()
    {
    	cout<<"You Win! <<endl;
    }
    
    void you_lose()
    {
    	cout << You Lose! Sucka! << endl;
    }
    
    void you_tie()
    {
    	cout <<"It's a Tie! << endl;
    }
    
    int main()
    {
        srand(time(NULL));
    
    	cout << "Welcome to ~ Rock Paper Scissors ~!! I assume you know how to play,";
        cout << " so lets begin. You are playing against the computer. Type 1 for";
        cout << " rock, 2 for paper,and 3 for scissors\n";
    
    	int userSel;
    	cin >> userSel;
    
    	cout <<endl;
    
    	int compSel = (rand() % 3) + 1;
    
    	if (userSel==1)
    	{
    		cout <<"You chose Rock." << endl;
    	}
    	else if (userSel==2)
    	{
    		cout <<"You chose Paper." << endl;
    	}
    	else if (userSel==3)
    	{
    		cout <<"You chose scissors." <<endl;
    	}
    	else
    	{
    		cout <<"Invalid choice." <<endl;
    		return 1;
    	}
    	}
    
    	if (compSel==1)
    	{
    		cout <<"Computer chose rock." << endl;
    	}
    	else if (compSel==2)
    	{
    		cout <<"Computer chose paper." <<endl;
    	}
    	else if (compSel==3)
    	{
    		cout <<"Computer chose scissors." <<endl;
    	}
    	
    cout <<end1;
    
    	if (userSel==compSel)
    	{
    		you_tie();
    	}
    	if (userSel==1)
    	{
    		if (compSel=2)
    		{
    			you_lose();
    		}
    		else if (compSel=3)
    		{
    			you_win();
    		}
    	}
    
    	else if (userSel==2)
    	{
    		if (compSel==1)
    		{
    			you_win();
    		}
    		else if (compSel==3)
    		{
    			you_lose();
    		}
    	}
    
    	else if (userSel==3)
    	{
    		if (compSel==1)
    		{
    			you_lose();
    		}
    		else if (compSel==2)
    		{
    			you_win();
    		)
    	}
    		
    }

  2. #2
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    You've some brackets mistakes, as you are ending your main() too before, check it please...
    I don't care if someone doesn't like me, i was not put on earth to entertain everyone.

    No King, no Queen, I am the ACE of battle.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    18
    What bracket mistakes? I am not sure what you are talking about...

  4. #4
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    Quote Originally Posted by mrsmoss3791 View Post
    Trying to make a rock, paper, scissors game but I keep on getting these error messages:
    error C2059: syntax error : 'else'
    error C2143: syntax error : missing ';' before '{'
    error C2447: '{' : missing function header (old-style formal list?)



    Here is my code:

    Code:
    #include <iostream>
    #include <ctime>
    using namespace std;
     
    void you_win()
    {
        cout<<"You Win! <<endl;
    }
     
    void you_lose()
    {
        cout << You Lose! Sucka! << endl;
    }
     
    void you_tie()
    {
        cout <<"It's a Tie! << endl;
    }
     
    int main()
    {
        srand(time(NULL));
     
        cout << "Welcome to ~ Rock Paper Scissors ~!! I assume you know how to play,";
        cout << " so lets begin. You are playing against the computer. Type 1 for";
        cout << " rock, 2 for paper,and 3 for scissors\n";
     
        int userSel;
        cin >> userSel;
     
        cout <<endl;
     
        int compSel = (rand() % 3) + 1;
     
        if (userSel==1)
        {
            cout <<"You chose Rock." << endl;
        }
        else if (userSel==2)
        {
            cout <<"You chose Paper." << endl;
        }
        else if (userSel==3)
        {
            cout <<"You chose scissors." <<endl;
        }
        else
        {
            cout <<"Invalid choice." <<endl;
            return 1;
        }
        }
     
        if (compSel==1)
        {
            cout <<"Computer chose rock." << endl;
        }
        else if (compSel==2)
        {
            cout <<"Computer chose paper." <<endl;
        }
        else if (compSel==3)
        {
            cout <<"Computer chose scissors." <<endl;
        }
     
    cout <<end1;
     
        if (userSel==compSel)
        {
            you_tie();
        }
        if (userSel==1)
        {
            if (compSel=2)
            {
                you_lose();
            }
            else if (compSel=3)
            {
                you_win();
            }
        }
     
        else if (userSel==2)
        {
            if (compSel==1)
            {
                you_win();
            }
            else if (compSel==3)
            {
                you_lose();
            }
        }
     
        else if (userSel==3)
        {
            if (compSel==1)
            {
                you_lose();
            }
            else if (compSel==2)
            {
                you_win();
            )
        }
     
    }
    Code:
    int main()
    {
        srand(time(NULL));
     cout << "Welcome to ~ Rock Paper Scissors ~!! I assume you know how to play,";
        cout << " so lets begin. You are playing against the computer. Type 1 for";
        cout << " rock, 2 for paper,and 3 for scissors\n";
     int userSel;
     cin >> userSel;
     cout <<endl;
     int compSel = (rand() % 3) + 1;
     if (userSel==1)
     {
      cout <<"You chose Rock." << endl;
     }
     else if (userSel==2)
     {
      cout <<"You chose Paper." << endl;
     }
     else if (userSel==3)
     {
      cout <<"You chose scissors." <<endl;
     }
     else
     {
      cout <<"Invalid choice." <<endl;
      return 1;
     }
     
     if (compSel==1)
     {
      cout <<"Computer chose rock." << endl;
     }
     else if (compSel==2)
     {
      cout <<"Computer chose paper." <<endl;
     }
     else if (compSel==3)
     {
      cout <<"Computer chose scissors." <<endl;
     }
     
    cout <<end1;
     if (userSel==compSel)
     {
      you_tie();
     }
     if (userSel==1)
     {
      if (compSel=2)
      {
       you_lose();
      }
      else if (compSel=3)
      {
       you_win();
      }
     }
     else if (userSel==2)
     {
      if (compSel==1)
      {
       you_win();
      }
      else if (compSel==3)
      {
       you_lose();
      }
     }
     else if (userSel==3)
     {
      if (compSel==1)
      {
       you_lose();
      }
      else if (compSel==2)
      {
       you_win();
      )
     }
      
    }
    Now, try this...
    I don't care if someone doesn't like me, i was not put on earth to entertain everyone.

    No King, no Queen, I am the ACE of battle.

  5. #5
    Registered User
    Join Date
    Mar 2011
    Posts
    18
    Now I am getting this message error:

    Now I am getting these error messages:
    error C2065: 'end1' : undeclared identifier
    error C2059: syntax error : ')'
    fatal error C1075: end of file found before the left brace '{'

  6. #6
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    First error: You've used end1 somewhere instead it is endl
    Second error: May be you are missing somewhere this brace ")"
    Third error: Not possible with my provided code. I don't know what's your whole code.
    Post your whole code here....
    I don't care if someone doesn't like me, i was not put on earth to entertain everyone.

    No King, no Queen, I am the ACE of battle.

  7. #7
    Registered User
    Join Date
    Mar 2011
    Posts
    18
    Code:
    #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;
    
    void you_win()
    {
    	cout<<"You Win! <<endl;
    }
    
    void you_lose()
    {
    	cout << You Lose! Sucka! << endl;
    }
    
    void you_tie()
    {
    	cout <<"It's a Tie! << endl;
    }
    
    int main()
    {
        srand(time(NULL));
     cout << "Welcome to ~ Rock Paper Scissors ~!! I assume you know how to play,";
        cout << " so lets begin. You are playing against the computer. Type 1 for";
        cout << " rock, 2 for paper,and 3 for scissors\n";
     int userSel;
     cin >> userSel;
     cout <<endl;
     int compSel = (rand() % 3) + 1;
     if (userSel==1)
     {
      cout <<"You chose Rock." << endl;
     }
     else if (userSel==2)
     {
      cout <<"You chose Paper." << endl;
     }
     else if (userSel==3)
     {
      cout <<"You chose scissors." <<endl;
     }
     else
     {
      cout <<"Invalid choice." <<endl;
      return 1;
     }
     
     if (compSel==1)
     {
      cout <<"Computer chose rock." << endl;
     }
     else if (compSel==2)
     {
      cout <<"Computer chose paper." <<endl;
     }
     else if (compSel==3)
     {
      cout <<"Computer chose scissors." <<endl;
     }
     
    cout <<endl;
    
     if (userSel==compSel)
     {
      you_tie();
     }
     if (userSel==1)
     {
      if (compSel=2)
      {
       you_lose();
      }
      else if (compSel=3)
      {
       you_win();
      }
     }
     else if (userSel==2)
     {
      if (compSel==1)
      {
       you_win();
      }
      else if (compSel==3)
      {
       you_lose();
      }
     }
     else if (userSel==3)
     {
      if (compSel==1)
      {
       you_lose();
      }
      else if (compSel==2)
      {
       you_win();
      )
     }
      
    }
    and these are the error messages:
    warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
    error C2059: syntax error : ')'
    fatal error C1075: end of file found before the left brace '{'

  8. #8
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,667
    In this part:
    Code:
     else if (userSel==3)
        {
            if (compSel==1)
            {
                you_lose();
            }
            else if (compSel==2)
            {
                you_win();
            )
        }
    Since that parens is there, that unbalances the curley braces and then you get the other error I think.

  9. #9
    Registered User
    Join Date
    Mar 2011
    Posts
    18
    I fixed two of the error messages and now this is my code:

    Code:
    #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;
    
    void you_win()
    {
    	cout<<"You Win! <<endl;
    }
    
    void you_lose()
    {
    	cout << You Lose! Sucka! << endl;
    }
    
    void you_tie()
    {
    	cout <<"It's a Tie! << endl;
    }
    
    int main()
    {
        srand((unsigned)time(0));
     cout << "Welcome to ~ Rock Paper Scissors ~!! I assume you know how to play,";
        cout << " so lets begin. You are playing against the computer. Type 1 for";
        cout << " rock, 2 for paper,and 3 for scissors\n";
     int userSel;
     cin >> userSel;
     cout <<endl;
     int compSel = (rand() % 3) + 1;
     if (userSel==1)
     {
      cout <<"You chose Rock." << endl;
     }
     else if (userSel==2)
     {
      cout <<"You chose Paper." << endl;
     }
     else if (userSel==3)
     {
      cout <<"You chose scissors." <<endl;
     }
     else
     {
      cout <<"Invalid choice." <<endl;
      return 1;
     }
     
     if (compSel==1)
     {
      cout <<"Computer chose rock." << endl;
     }
     else if (compSel==2)
     {
      cout <<"Computer chose paper." <<endl;
     }
     else if (compSel==3)
     {
      cout <<"Computer chose scissors." <<endl;
     }
     
    cout <<endl;
    
     if (userSel==compSel)
     {
      you_tie();
     }
     if (userSel==1)
     {
      if (compSel=2)
      {
       you_lose();
      }
      else if (compSel=3)
      {
       you_win();
      }
     }
     else if (userSel==2)
     {
      if (compSel==1)
      {
       you_win();
      }
      else if (compSel==3)
      {
       you_lose();
      }
     }
     else if (userSel==3)
     {
      if (compSel==1)
      {
       you_lose();
      }
      else if (compSel==2)
      {
       you_win();
      }
     }
      
    }
    and these are the error messages:
    error C2059: syntax error : '<<'
    error C2001: newline in constant
    error C2143: syntax error : missing ';' before '}'

    btw, i really appreciate you taking the time to help me with this program!

    This is the final code:

    Code:
    #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;
    
    void you_win()
    {
    	cout<<"You Win!" <<endl;
    }
    
    void you_lose()
    {
    	cout << "You Lose! Sucka!" << endl;
    }
    
    void you_tie()
    {
    	cout <<"It's a Tie!" << endl;
    }
    
    int main()
    {
        srand((unsigned)time(0));
     cout << "Welcome to ~ Rock Paper Scissors ~!! I assume you know how to play,";
        cout << " so lets begin. You are playing against the computer. Type 1 for";
        cout << " rock, 2 for paper,and 3 for scissors\n";
     int userSel;
     cin >> userSel;
     cout <<endl;
     int compSel = (rand() % 3) + 1;
     if (userSel==1)
     {
      cout <<"You chose Rock." << endl;
     }
     else if (userSel==2)
     {
      cout <<"You chose Paper." << endl;
     }
     else if (userSel==3)
     {
      cout <<"You chose scissors." <<endl;
     }
     else
     {
      cout <<"Invalid choice." <<endl;
      return 1;
     }
     
     if (compSel==1)
     {
      cout <<"Computer chose rock." << endl;
     }
     else if (compSel==2)
     {
      cout <<"Computer chose paper." <<endl;
     }
     else if (compSel==3)
     {
      cout <<"Computer chose scissors." <<endl;
     }
     
    cout <<endl;
    
     if (userSel==compSel)
     {
      you_tie();
     }
     if (userSel==1)
     {
      if (compSel=2)
      {
       you_lose();
      }
      else if (compSel=3)
      {
       you_win();
      }
     }
     else if (userSel==2)
     {
      if (compSel==1)
      {
       you_win();
      }
      else if (compSel==3)
      {
       you_lose();
      }
     }
     else if (userSel==3)
     {
      if (compSel==1)
      {
       you_lose();
      }
      else if (compSel==2)
      {
       you_win();
      }
     }
      
    }
    everything works now..thanks!
    Last edited by mrsmoss3791; 03-20-2011 at 11:29 PM.

  10. #10
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,667
    Mrs Moss, meet my compiler digest:
    C:\Documents and Settings\Owner\My Documents\sandbox\main.cpp|8|warning: missing terminating " character|
    C:\Documents and Settings\Owner\My Documents\sandbox\main.cpp|8|error: missing terminating " character|
    C:\Documents and Settings\Owner\My Documents\sandbox\main.cpp|18|warning: missing terminating " character|
    C:\Documents and Settings\Owner\My Documents\sandbox\main.cpp|18|error: missing terminating " character|
    C:\Documents and Settings\Owner\My Documents\sandbox\main.cpp||In function 'void you_win()':|
    C:\Documents and Settings\Owner\My Documents\sandbox\main.cpp|9|error: expected primary-expression before '}' token|
    C:\Documents and Settings\Owner\My Documents\sandbox\main.cpp|9|error: expected ';' before '}' token|
    C:\Documents and Settings\Owner\My Documents\sandbox\main.cpp||In function 'void you_lose()':|
    C:\Documents and Settings\Owner\My Documents\sandbox\main.cpp|13|error: 'You' was not declared in this scope|
    C:\Documents and Settings\Owner\My Documents\sandbox\main.cpp|13|error: expected ';' before 'Lose'|
    C:\Documents and Settings\Owner\My Documents\sandbox\main.cpp||In function 'void you_tie()':|
    C:\Documents and Settings\Owner\My Documents\sandbox\main.cpp|19|error: expected primary-expression before '}' token|
    C:\Documents and Settings\Owner\My Documents\sandbox\main.cpp|19|error: expected ';' before '}' token|
    C:\Documents and Settings\Owner\My Documents\sandbox\main.cpp||In function 'int main()':|
    C:\Documents and Settings\Owner\My Documents\sandbox\main.cpp|70|warning: suggest parentheses around assignment used as truth value|
    C:\Documents and Settings\Owner\My Documents\sandbox\main.cpp|74|warning: suggest parentheses around assignment used as truth value|
    ||=== Build finished: 8 errors, 4 warnings ===|
    Useful things about this digest include the line number, which can be helpful in determining where an error is. Now, my compiler also puts the problems you are having differently, but this is your input.

    I suggest many things, including:
    *carefully reviewing your syntax and surrounding all your strings with "
    *carefully reviewing your syntax and reviewing the if statements, as a couple of the warnings suggest you used = instead of == in the condition
    *carefully going over your syntax to address the other syntax issues
    *and then try compiling again

  11. #11
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    @whiteflags: Why you disabled all your options in your profile? A general question.
    I don't care if someone doesn't like me, i was not put on earth to entertain everyone.

    No King, no Queen, I am the ACE of battle.

  12. #12
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,667
    If by options you mean things like private messaging, then it's because messaging me is a privilege and not a right. I decided to try keeping things public a while ago.

  13. #13
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    Okay also i am talking about requests... Anyways, good luck.
    I don't care if someone doesn't like me, i was not put on earth to entertain everyone.

    No King, no Queen, I am the ACE of battle.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Umm... help me find a Game Engine?
    By Hmph in forum Game Programming
    Replies: 8
    Last Post: 03-20-2011, 10:07 AM
  2. Replies: 8
    Last Post: 10-24-2007, 05:46 PM
  3. need help with rock paper scissors program
    By Mshock in forum C Programming
    Replies: 3
    Last Post: 04-22-2006, 07:44 AM
  4. Paper Scissors Rock v0.1
    By Kirdra in forum Game Programming
    Replies: 2
    Last Post: 09-14-2002, 11:32 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21