Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
196 changes: 99 additions & 97 deletions RockPaperScissor/main.cpp
Original file line number Diff line number Diff line change
@@ -1,109 +1,111 @@
#include<iostream>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#include

#include <iostream>
using namespace std;

int main()
{
int a[3] = {1, 2, 3};
int w;
string b[3] = {"Rock", "Paper", "Scissor"};
int uc, cc, c;
int w, cnt = 0;
string b[3] = {"Rock", "Paper", "Scissor"};
int a[3] = { 1, 2, 3 };
int uc, cc, c;

while(true)
{
cout<<"Enter 1 for Rock.\n";
cout<<"Enter 2 for Paper.\n";
cout<<"Enter 3 for Scissor.\n";
cout<<"Enter your choice:\n";
cin>>uc;

cc = a[(rand() % 3)]-1;
while (true)
{
cout << "Enter 1 for Rock.\n";
cout << "Enter 2 for Paper.\n";
cout << "Enter 3 for Scissor.\n";
cout << "Enter your choice:\n";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cout << "Enter your choice : " ;

cin >> uc;

cout<<"You chose: "<<b[uc-1]<<"\n";
cout<<"Computer choose: "<<b[cc]<<"\n";
cc = a[(rand() % 3)] - 1;//

if(a[uc-1] == 1)
{
if(a[cc] == 3)
{
w = 1;
}
else if(a[cc] == 2)
{
w = 0;
}
else
{
w = -1;
}
}
else if(a[uc-1] == 2)
{
if(a[cc] == 1)
{
w = 1;
}
else if(a[cc] == 3)
{
w = 0;
}
else
{
w = -1;
}
}
else
{
if(a[cc] == 2)
{
w = 1;
}
else if(a[cc] == 1)
{
w = 0;
}
else
{
w = -1;
}
}
cout << "You chose: " << b[uc - 1] << "\n";
cout << "Computer choose: " << b[cc] << "\n";

if(w == 1)
{
cout<<"You won!\n";
}
else if(w == 0)
{
cout<<"You lose!\n";
}
else
{
cout<<"Tie!\n";
}
if (a[uc - 1] == 1)
{
if (a[cc] == 3)
{
w = 1;
}
else if (a[cc] == 2)
{
w = 0;
}
else
{
w = -1;
}
}
else if (a[uc - 1] == 2)
{
if (a[cc] == 1)
{
w = 1;
}
else if (a[cc] == 3)
{
w = 0;
}
else
{
w = -1;
}
}
else
{
if (a[cc] == 2)
{
w = 1;
}
else if (a[cc] == 1)
{
w = 0;
}
else
{
w = -1;
}
}

cout<<"Do you want to play again?\n";
cout<<"Enter 1 for YES.\n";
cout<<"Enter 2 for NO.\n";
cin>>c;
if (w == 1)
{
cnt++;
cout << "You won!\n";
}
else if (w == 0)
{
if(cnt>0)
cnt--;
cout << "You lose!\n";
}
else
{
cout << "Tie!\n";
}
cout << "Your score = " << cnt << endl;
cout << "Do you want to play again?\n";
cout << "Enter 1 for YES.\n";
cout << "Enter 2 for NO.\n";
cin >> c;

if(c == 2)
{
cout<<"Session being terminated...\n";
exit(0);
}
else if(c != 1)
{
cout<<"Wrong choice! Session being terminated...\n";
exit(0);
}
else
{
cout<<"\e[1;1H\e[2J";
cc=0;
uc=0;
}
if (c == 2)
{
cout << "Session being terminated...\n";
cout << "Your Final Score = " << cnt;
exit(0);
}
else if (c != 1)
{
cout << "Wrong choice! Session being terminated...\n";
exit(0);
}
else
{
cout << "\e[1;1H\e[2J";
cc = 0;
uc = 0;
}


}

return 0;
}
return 0;
}