mercredi 11 mars 2020

Im having trouble with if statements

I keep getting "expected initializer before 'if'" errors I was wondering if anyone can help me with that problem?I have this homework assignment that basically asks you to run a rock paper scissors game with 2 players.

#include <iostream>

int main()
{
  int x, y;

  std::cout << "Player 1 enter rock(1), paper(2), scissors(3):";
  std::cin >> x;
  std::cout << "Player 2 enter rock(1), paper(2), scissors(3):";
  std::cin >> y;
}
if ( x==1 ) and ( y==2 ) {
  std::cout << "Player 2 Wins! Paper Covers Rock!!\n";
}
else if ( x==1 ) and ( y==3 ) {
  std::cout << "Player 1 Wins! Rock Breaks Scissors!!\n";
}
else if ( x==1 ) and (x==1) {
  std::cout << "Tie with rock!\n";
}
else if ( x==2 ) and ( y==3 ) {
  std::cout <<  "Player 2 Wins! Scissors Cut Paper!!\n";
}
else if ( x==2 ) and ( y==1 ) {
  std::cout << "Player 1 wins! Paper Covers Rock!!\n";
}
else if ( x==2 ) and ( y==2 ) {
  std::cout << "Tie with Paper!\n"; 
}
else if ( x==3 ) and ( y==1 ) {
  std::cout << "Player 2 wins! Rock Breaks Scissors!!\n";
}
else if ( x==3 ) and ( y==2 ) {
  std::cout << "Player 1 wins! Scissors Cut Paper!!\n";
}
else if ( x==3 ) and ( y==3 ) {
  std::cout << "Tie with Scissors!";
}
else if (x>3){
 std::cout << "Invalid move!!\n";
}
else if (y>3){
  std::cout << "Invalid move!!\n";
}
return 0
}

Aucun commentaire:

Enregistrer un commentaire