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(); ) } }



LinkBack URL
About LinkBacks



