C++ program for playing Rock-Paper-Scissor

 C++ program for playing Rock-Paper-Scissor against the Computer.

-Dinesh kumar E

This is an interesting c++ program to play stone paper scissor.
Hope you will enjoy it.

#include<iostream>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int main ()
{
string name;
int i,comp,user,round,user1,comp1,check,cscore=0,uscore=0,tie;
float cpercent,upercent;
cout<<"Rock-Paper-Scissor"<<endl;
cout<<"Main menu"<<endl;
cout<<"================================"<<endl<<endl;
cout<<"Enter 1 for Rock"<<endl<<"Enter 2 for Paper"<<endl<<"Enter 3 for Scissor"<<endl;
cout<<"\n\n================================"<<endl;
cout<<"Enter Your Name : ";
cin>>name;
cout<<"\n Sweet name"<<endl;
cout<<"================================"<<endl<<endl;
cout<<"Let's Start the game..."<<name<<endl<<endl;
cout<<"Enter the number of rounds :";
cin>>round;
for(i=0;i<round;i++)
{
cout<<"\nEnter your choice : ";
cin>>user;
user1=user*7;
comp=(rand()%3);
comp1=comp+7;
check=comp1*user1;
switch(check)
{
case 49:
{
cout<<"Computer choice is Rock"<<endl<<endl;
cout<<"It's a tie"<<endl;
cout<<"--------------"<<endl<<endl;
break;
}
case 56:
{
cout<<"Computer choice is Paper"<<endl<<endl;
cout<<"Computer Won The Match"<<endl;
cout<<"--------------"<<endl<<endl;
cscore=cscore+1;
break;
}
case 63:
{
cout<<"Computer choice is Scissor"<<endl<<endl;
cout<<name<<" Won the game"<<endl;
cout<<"--------------"<<endl<<endl;
uscore=uscore+1;
break;
}
case 98:
{
cout<<"Computer choice is Rock"<<endl<<endl;
cout<<name<<" Won the game"<<endl;
cout<<"--------------"<<endl<<endl;
uscore=uscore+1;
break;
}
case 112:
{
cout<<"Computer choice is Paper"<<endl<<endl;
cout<<"It's a tie"<<endl;
cout<<"--------------"<<endl<<endl;
break;
}
case 126:
{
cout<<"Computer choice is Scissor"<<endl<<endl;
cout<<"Computer Won The Match"<<endl;
cout<<"--------------"<<endl<<endl;
cscore=cscore+1;
break;
}
case 147:
{
cout<<"Computer choice is Rock"<<endl<<endl;
cout<<"Computer Won The Match"<<endl;
cout<<"--------------"<<endl<<endl;
cscore=cscore+1;
break;
}
case 168:
{
cout<<"Computer choice is Paper"<<endl<<endl;
cout<<name<<" Won the game"<<endl;
cout<<"--------------"<<endl<<endl;
uscore=uscore+1;
break;
}
case 189:
{
cout<<"Computer choice is Scissor"<<endl<<endl;
cout<<"It's a tie"<<endl;
cout<<"--------------"<<endl<<endl;
break;
}
default:
{
cout<<"Invalid Move"<<endl;
cout<<"Try again"<<endl;
}
}
}
cout<<"================================"<<endl<<endl;
cout<<name<<" score is "<<uscore<<endl;
cout<<"computer's score is "<<cscore<<endl;
tie=round-(uscore+cscore);
cout<<"No of tie "<<tie;
cout<<"\n\n================================"<<endl<<endl;
getchar();
}

 

Comments

Popular Posts