Hi i dont get why this doesn't work.... Could someone lend me a hand?
The code works fine when changing numbers higher than 10 into Jack, Queen, King and Ace the first time, but the second time even though it's the same code it doesn't work... and also it always assigns the same values to both the computer and the human...
#include <ctime>
#include <cstdlib>
#include <iostream>
usingnamespace std;
int main()
{
srand(time (0));
int a = (2 + rand() % 13);
int b = (rand() % 4);
cout << "The computer's card is a ";
if (a <= 10) cout << a;
if (a == 11) cout << "Jack";
if (a == 12) cout << "Queen";
if (a == 13) cout << "King";
if (a == 14) cout << "Ace";
if (b == 0) cout << " of Spades." << endl;
if (b == 1) cout << " of Diamonds." << endl;
if (b == 2) cout << " of Hearts." << endl;
if (b == 3) cout << " of Clubs." << endl;
//end of computer card calculation
int c = (2 + rand() % 13);
int d = (rand() % 4);
cout << "Human's card is a ";
if (c <= 10) cout << a;
if (c == 11) cout << "Jack";
if (c == 12) cout << "Queen";
if (c == 13) cout << "King";
if (c == 14) cout << "Ace";
if (d == 0) cout << " of Spades." << endl;
if (d == 1) cout << " of Diamonds." << endl;
if (d == 2) cout << " of Hearts." << endl;
if (d == 3) cout << " of Clubs." << endl;
//human card calculation ends
if (a == c) cout << "It's a tie!" << endl;
if (a >= c) cout << "Computer wins!" << endl;
if (a <= c) cout << "Human wins!" << endl;
cout << endl;
}
What would get printed if you and the computer had the same face card? All three lines would get printed, cause they are all true. In order for no tie, one card must have a higher value, so the program should be checking only if either players card is the higher of the two, or of equal value.