C++ Program : Paper-Rock-scissor


Write a program to score the Paper-Rock-Scissor Game


#include<iostream>


int main()


{

                char repeat;

   do

                                {

                                                char a,b;

                cout<<"This is a Paper-Rock-Scissors Competation Program \n";

                cout<<"Instructions:\n";

                                                cout<<"     Press P for Paper\n     Press R for Rock\n     Press S for Scissors\n";

                                                cout<<"Player 1:\n";

                                                cin>>a;

                                                cout<<"Player 2:\n";

                                                cin>>b;


      if ((a=='r' || a=='R') && (b=='s' || b=='S'))

         {

                                                cout<<" Rock breaks scissors\n Player 1 wins!\n";

         cout<<" Congratulations!\n";

         }

      else if ((a=='r' || a=='R') && (b=='p' || b=='P'))

                {

                                                cout<<" Paper covers rock\n Player 2 wins!\n";

         cout<<" Congratulations!\n";

         }

      else if ((a=='r' || a=='R') && (b=='r' || b=='R'))

                                                cout<<"It's a tie!\n";

      else if ((a=='p' || a=='P') && (b=='s' || b=='S'))

                                                {

         cout<<" Scissors cut paper\n Player 2 wins!\n";

         cout<<" Congratulations!\n";

         }

      else if ((a=='p' || a=='P') && (b=='r' || b=='R'))

         {

                                                cout<<" Paper covers rock\n Player 1 wins!\n";

         cout<<" Congratulations!\n";

         }

      else if ((a=='P' || a=='P') && (b=='p' || b=='P'))

                                                cout<<"It's a tie!\n";

                                else if ((a=='s' || a=='S') && (b=='P' || b=='p'))

                                                {

         cout<<" Scissors cut paper\n Player 1 wins!\n";

         cout<<" Congratulations!\n";

         }

                                else if ((a=='s' || a=='S') && (b=='R' || b=='r'))

                                                {

         cout<<" Rock breaks scissors\n Player 2 wins!\n";

         cout<<" Congratulations!\n";

         }

                                else if ((a=='s' || a=='S') && (b=='s' || b=='S'))

                                                cout<<"It's a tie!\n";

         cout<<"Do you want to play again? [Y/N]\n";

         cin>>repeat;

      }

      while ((repeat == 'y' || repeat=='Y'));

      cout<<"Thank You for Playing!\n";



cin.get ();

cin.get ();


return 0;

}
Share:

No comments:

Post a Comment

Thanks for Suggestion / Comment!

God Bless!

Our Sponsor

Popular Post

Blog Archive