1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>
using namespace std;
void computerChoice(int type2, int counter2, int losses2);
void continuing(int counter3, int losses3);
void statistics(int counter4, int losses4);
int main(){
int type1 = 0, counter1 = 0, losses1 = 0;
cout << "-= Rock, Paper, Scissors =-\n\n(1) Rock.\n(2) Paper.\n(3) Scissors.\n(4) Statistics.\n(5) Quit.\n\n"; cin >> type1;
switch(type1){
case 1:
computerChoice(type1, counter1, losses1);
break;
case 2:
computerChoice(type1, counter1, losses1);
break;
case 3:
computerChoice(type1, counter1, losses1);
break;
case 4:
statistics(counter1, losses1);
break;
case 5:
cout << "Goodbye!";
break;
default:
system("CLS");
main();
}
return(0);
}
void continuing(int counter3, int losses3){
int type3;
cout << "-= Rock, Paper, Scissors =-\n\n(1) Rock.\n(2) Paper.\n(3) Scissors.\n(4) Statistics.\n(5) Quit.\n\n"; cin >> type3;
switch(type3){
case 1:
computerChoice(type3, counter3, losses3);
break;
case 2:
computerChoice(type3, counter3, losses3);
break;
case 3:
computerChoice(type3, counter3, losses3);
break;
case 4:
statistics(counter3, losses3);
break;
case 5:
cout << "Goodbye!";
break;
default:
system("CLS");
main();
}
}
void computerChoice(int type2, int counter2, int losses2){
srand(time(0));
int x = 1+(rand()%3);
switch(x){
case 1:
cout << "The computer chose rock!" << endl;
if(type2 == 1){
cout << "No one wins!" << endl;
}
if(type2 == 2){
cout << "Paper covers rock; you win!" << endl;
counter2++;
}
if(type2 == 3){
cout << "Rock breaks scissors; you lose!" << endl;
losses2++;
}
break;
case 2:
cout << "The computer chose paper!" << endl;
if(type2 == 1){
cout << "Paper covers rock; you lose!" << endl;
losses2++;
}
if(type2 == 2){
cout << "No one wins!" << endl;
}
if(type2 == 3){
cout << "Scissors cut paper; you win!" << endl;
counter2++;
}
break;
case 3:
cout << "The computer chose scissors!" << endl;
if(type2 == 1){
cout << "Rock breaks scissors; you win!" << endl;
counter2++;
}
if(type2 == 2){
cout << "Scissors cut paper; you lose!" << endl;
losses2++;
}
if(type2 == 3){
cout << "No one wins!" << endl;
}
break;
}
cout << "Press enter to go back to the menu!" << endl;
cin.get();
cin.get();
system("CLS");
continuing(counter2, losses2);
}
void statistics(int counter4, int losses4){
cout << "Welcome to the statistics board!\n" << endl;
if(counter4 == 0 || losses4 == 0){
cout << "Wins: " << counter4 << "\nLosses: " << losses4 << "\n\n";
}else{
double resultat = counter4/losses4;
cout << "Wins: " << counter4 << "\nLosses: " << losses4 << "\nWin/Loss-ratio: " << fixed << setprecision(2) << resultat << "\n\n";
}
cout << "Press enter to go back to the menu!" << endl;
cin.get();
cin.get();
system("CLS");
continuing(counter4, losses4);
}
|