### 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:

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697`` ``````#include #include #include 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!"<>n; srand(n); card = rand()%13+1; lastcard = card; cout<<"The first card is: "; if (card==1) { cout<<"Ace"<>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"<>user; } put<
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.