#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
int main(){
   string ans ="";
   string ans2 ="";
   char ch;
   cout << "Enter 1stplayer:\n";
   ch = _getch();
   while(ch != 13){//character 13 is enter
      ans.push_back(ch);
      cout << '*';
      ch = _getch();
      }
   char chs;
   cout << "\nEnter 2ndplayer:\n";
   chs = _getch();
   while(chs != 13){//character 13 is enter
      ans2.push_back(chs);
      cout << '*';
      chs = _getch();
}
   {if((ans=="r"||ans=="R")&&(ans2=="s"||ans2=="S"))
   cout << "\nRock breakes scissor; First player wins!\n";
   else if((ans=="p"||ans=="P")&&(ans2=="r"||ans2=="R"))
   cout<<"\nPaper covers rock; First player wins!"<<endl;
   else if((ans=="s"||ans=="S")&&(ans2=="p"||ans2=="P"))
   cout<<"\nScissors cut paper; First player wins!"<<endl;
   else if((ans2=="r"||ans2=="R")&&(ans=="s"||ans=="S"))
   cout<<"\nRock breakes scissor; Second player wins!"<<endl;
   else if((ans2=="p"||ans2=="P")&&(ans=="r"||ans=="R"))
   cout<<"\nPaper covers rock; Second player wins!"<<endl;
   else if((ans2=="s"||ans2=="S")&&(ans=="p"||ans=="P"))
   cout<<"\nScissors cut paper; Second player wins!"<<endl;
   else
   cout<<"Nobody wins\n";
}
   system("pause");
   return 0;
}

how can i make the game play continue after 1st game done?

Edited 6 Years Ago by Nick Evan: n/a

Wrap the game in a loop. It's easier if the game is in a different function from main:

#include <iostream>
#include <ctype.h>
#include <conio.h>

using namespace std;

void play_game()
{
    cout << "Playing game..." << endl;
}

int main()
{
    do
    {
        play_game();
        cout << "Again? (y/n)> " << flush;
    }
    while (tolower(getch()) == 'y');
}
This article has been dead for over six months. Start a new discussion instead.