diff --git a/RockPaperScissor/main.cpp b/RockPaperScissor/main.cpp index 21a46cc..26b76ff 100644 --- a/RockPaperScissor/main.cpp +++ b/RockPaperScissor/main.cpp @@ -1,109 +1,111 @@ -#include +#include 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"; + cin >> uc; - cout<<"You chose: "<>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; +} \ No newline at end of file