-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA Card Game Example.cpp
More file actions
72 lines (52 loc) · 1.39 KB
/
A Card Game Example.cpp
File metadata and controls
72 lines (52 loc) · 1.39 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
#include <iostream>
using namespace std;
//
const int clubs = 0;
const int diamonds = 1;
const int hearts = 2;
const int spades = 3;
const int jack = 11;
const int queen = 12;
const int king = 13;
const int ace = 14;
struct Card
{
int number;
int suit;
};
int main()
{
setlocale(LC_ALL, "italian");
Card temp, chosen, prize;
int position;
Card card1 = { 7, clubs };
cout << "Card 1 is the 7 of clubs\n";
Card card2 = { jack, hearts };
cout << "Card 2 is the jack of hearts\n";
Card card3 = { ace, spades };
cout << "Card 3 is the ace of spades\n";
prize = card3; // i valori che si trova al interno di questa variabile
// sono quelli vincenti
cout << "\nI'm swapping card 1 and card 3"; // si mescolano i valori
temp = card3; card3 = card1; card1 = temp;
cout << "\nI'm swapping card 2 and card 3";
temp = card3; card3 = card2; card2 = temp;
cout << "\nI'm swapping card 1 and card 2";
temp = card2; card2 = card1; card1 = temp;
cout << "\n\nNow, where (1, 2 or 3) is the ace of spades? ";
cin >> position;
switch (position)
{
case 1: chosen = card1;
break;
case 2: chosen = card2;
break;
case 3: chosen = card3;
break;
}
if ((chosen.number == prize.number) && (chosen.suit == prize.suit)) // non si può scrivere chosen == prize
cout << "You win!" << endl;
else
cout << "Sorry, you lose" << endl;
return 0;
}