-
Notifications
You must be signed in to change notification settings - Fork 353
Expand file tree
/
Copy pathmain_05_05.cpp
More file actions
98 lines (84 loc) · 2.05 KB
/
main_05_05.cpp
File metadata and controls
98 lines (84 loc) · 2.05 KB
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
#include <iostream>
std::string mapping(int choosen)
{
std::string word = "";
switch (choosen)
{
case 1:
word="Schere";
break;
case 2:
word="Stein";
break;
case 3:
word="Papier";
break;
}
return word;
}
int main()
{
bool weiterspielen = true;
while (weiterspielen==true)
{
int comp=0;
int usr=0;
std::string winner={};
while((usr<1)||(usr>3))
{
std::cout << "Wählen Sie zwischen:\n Schere(1)\n Stein(2)\n Papier(3):" << std::endl;
std::cin>> usr;
if ((usr < 1)
|| (usr > 3))
std::cout << "Falsche Eingabe!"<< std::endl;
}
comp = rand() %3 + 1;
/* usr comp result
1 1 equal
1 2 comp
1 3 usr
2 1 usr
2 2 equal
2 3 comp
3 1 comp
3 2 usr
3 3 equal
*/
if(usr==comp)
{
winner="Niemand (Unentschieden)";
}else if((usr == 1 && comp == 3)||
(usr == 2 && comp == 1)||
(usr == 3 && comp == 2)){
winner="der Spieler";
}
else{
winner="der Computer";
}
std::cout<< "Der Spieler hat " << mapping(usr) << " ausgewählt." << std::endl;
std::cout << "Der Computer hat " << mapping(comp) << " ausgewählt." << std::endl;
std::cout << "Es gewinnt " << winner << std::endl;
char choice=NULL;
weiterspielen = NULL;
std::cout << "Möchten Sie noch einmal spielen? (Drücken Sie 'J' für Ja oder 'N' für Nein): ";
while (choice != 'N' && choice != 'n' && choice != 'J' && choice != 'j')
{
std::cin >> choice;
if (choice == 'N' || choice == 'n')
{
std::cout << "Das Spiel wird beendet." << std::endl;
weiterspielen=false;
}
else if(choice == 'J' || choice == 'j')
{
std::cout << "Sie spielen noch einmal" << std::endl;
weiterspielen=true;
// ...
}
else{
weiterspielen=NULL;
}
}
}
return 0;
}