hey everyone I have a C++ game code that i wrote to run rock paper, scissor,
i need to convert it into C can anyone help me with this..
Code:
#include <iostream>
using namespace std;
#include <ctime>
int main(void)
{
srand((unsigned int) time(0));
int guess = 0, low = 0, high = 3, win = 0, lose = 0;
cout << "\t\t\tRock Paper Siccors\n\n";
char choice = 0 ;
//round loop
for (int i =0; choice != 'q' && choice != 'Q'; i++)
{
guess = (rand() % (high - low +1)) +low;
cout << "Please choice one of the following:\n";
cout << "\t(R)ock\t(P)aper\t(S)cissors (Q)uit\n";
cout << "Round " << i + 1 << endl;
cin.get(choice);
while(cin.get() != '\n'){};
switch(choice)
{
case 'r': case 'R':
cout << "You choose Rock.\n";
if (guess == 1)
{
cout << "The computer choose Rock, its a tie!\n\n";
}
else if (guess == 2)
{
cout << "The computer choose Paper, you lose!\n\n";
++lose;
}
else
{
cout << "The computer choose Scissors, you win!\n\n";
++win;
}
cout <<"The current score:\tWins: " << win << " Loses: " << lose << endl;
system("pause");
system("cls");
break;
case 'p': case 'P':
cout << "You choose Paper.\n";
if (guess == 1)
{
cout << "The computer choose Rock, you win!\n\n";
++win;
}
else if (guess == 2)
{
cout << "The computer choose Paper, its a tie!\n\n";
}
else
{
cout << "The computer choose Scissors, you lose!\n\n";
++lose;
}
cout <<"The current score:\tWins: " << win << " Loses: " << lose << endl;
system("pause");
system("cls");
break;
case 's': case 'S':
cout << "You choose Scissors.\n";
if (guess == 1)
{
cout << "The computer choose Rock, you lose!\n\n";
++lose;
}
else if (guess == 2)
{
cout << "The computer choose Paper, you win!\n\n";
++win;
}
else
{
cout << "The computer choose Scissors, its a tie!\n\n";
}
cout <<"The current score:\tWins: " << win << " Loses: " << lose << endl;
system("pause");
system("cls");
break;
case 'q': case 'Q':
cout << "You played through " << i + 1 << " Round(s)\n";
cout <<"The final scores:\tWins: " << win << " Loses: " << lose << endl;
break;
default:
cout << "Please choose an avalible selection.\n";
break;
}
}
return 0;
}