C++ program for rock paper scissors game

#include <iostream>

using namespace std;

void play(char x,char y)

    {

        if((x=='r'||x=='R')&&(y=='r'||y=='R'))

        {

            cout<<"It's a Draw";

        }

        else if((x=='p'||x=='P')&&(y=='p'||y=='P'))

        {

            cout<<"It's a Draw";

        }

        else if((x=='s'||x=='S')&&(y=='s'||y=='S'))

        {

            cout<<"It's a Draw";

        }

        else if((x=='r'||x=='R')&&y=='p')

        {

            cout<<"YOU LOST!";

        }

        else if((x=='r'||x=='R')&&y=='s')

        {

            cout<<"YOU WON!";

        }

        else if((x=='p'||x=='P')&&y=='r')

        {

            cout<<"YOU WON!";

        }

        else if((x=='p'||x=='P')&&y=='s')

        {

            cout<<"YOU LOST!";

        }

        else if((x=='s'||x=='S')&&y=='r')

        {

            cout<<"YOU LOST!";

        }

        else if((x=='s'||x=='S')&&y=='p')

        {

            cout<<"YOU WON!";

        }

        else

        cout<<"please choose valid option";

    }

int main() 

{

    start:

    char you;

    char comp;

    srand(time(NULL));

    int num = rand()%3+1;

    if(num==1)

    comp='r';

    if(num==2)

    comp='p';

    if(num==3)

    comp='s';

    cout<<"Enter \nr for rock\np for paper\ns for scissors\n";

    cin>>you;

    cout<<"________________\n";

    cout<<"you chose : "<<you<<endl;

    cout<<"computer chose : "<<comp<<endl;

    cout<<"________________\n";

    play(you,comp);

    cout<<"\n________________\n";

    end:

    int choice;

    cout<<"press 0 to exit and 1 to play again : ";

    cin>>choice;

    if(choice==0)

    {

        cout<<"Thank You for playing this game";

    }

    else if(choice==1)

    {

        goto start;

    }

    else

    {

        cout<<"please choose valid option\n";

        goto end;

    }

    return 0;

}


OUTPUT




Comments