Guess if the next card is higher or lower?

Usually I can get through my homework assignments no problem...not sure why I am having trouble. I need to display a card (Ace-King...1-13) and the user needs to guess if the next card will be higher. Here is my code:

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
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{

int n, c, card, user, right=0, lastcard;
ofstream put ("Output.txt");

cout<<"Enter a seed to start us off!"<<endl;
cin>>n;

srand(n);

card = rand()%13+1;
lastcard = card;

cout<<"The first card is: ";
if (card==1)
{
	cout<<"Ace"<<endl;
}
else if (card==11)
{
	cout<<"Jack"<<endl;
}
else if (card==12)
{
	cout<<"Queen"<<endl;
}
else if (card==13)
{
	cout<<"King"<<endl;
}

else
{
	cout<<card<<endl;
}

cout<<"Will the next card be higher or lower? 0 == Higher -- 1 == Lower.";
cin>>user;



for (c=1;c<=4;c++)
{
cout<<"The next card is: ";

card = rand()%13+1;


if (card!=1 && card > lastcard && user == 0)
{
	right++;
}
else if (card!=1 && card < lastcard && user == 1)
{
	right++;
}


if (card==2)
{
	cout<<"Ace"<<endl;
}
else if (card==11)
{
	cout<<"Jack"<<endl;
}
else if (card==12)
{
	cout<<"Queen"<<endl;
}
else if (card==13)
{
	cout<<"King"<<endl;
}

else
{
	cout<<card<<endl;
}

lastcard=card;

cout<<"Will the next card be higher or lower? 0 == Higher -- 1 == Lower.";
cin>>user;

}


put<<fixed<<setprecision(2)<<right/5<<"% right."<<endl;

	return(0);
}
Last edited on
My RIGHT variable is coming out to 0 every time.

Thanks for the help.
Maybe (card < lastcard && user != 0) or (card > lastcard && user != 1) ?
I still cannot figure out how to make it so that the variable "right" will actually add 1 each time the user gets it right...

Perhaps it has something to do with my lastCard variable.

Anyone have any idea?
Last edited on
Try:

put<<fixed<<setprecision(2)<<double(right/5)<<"% right."<<endl;
Gah! Thank you! I had it set as an integer!
Topic archived. No new replies allowed.