Please help me with this peice of code

Pages: 12
I am trying to make a program that can perform basic strategy in blackjack, I have all the numbers set up, but it does not work, please tell me when I am doing wrong, thank you.

Sadly the program is too ling, so i will post it in the following 2 posts.

#include <iostream>

using namespace std;

int d;
int y;


int main()
{
    cout<<"Hello! My name is BlackBot, Please enter the Dealer's First Card, Do not use faces, enter them as 10. To enter an ace, enter 1";
    cin>> d; 
    cin.ignore(); 
    cout<<"Please enter your hand as a number.\nIf you have a soft hand, enter a 1 after the number, for example, a soft 20 is 201.\nIf you have a pair, enter a 2 after the number that represents the card, for example a pair of aces would be 12"; 
    cin>> y; 
    cin.ignore(); 
    cin.get(); 
    if (d == 2 && y == 21)
    cout<<"Stand";
    if (d == 2 && y == 20)
    cout<<"Stand";
    if (d == 2 && y == 19)
    cout<<"Stand";
    if (d == 2 && y == 18)
    cout<<"Stand";
    if (d == 2 && y == 17)
    cout<<"Stand";
    if (d == 2 && y == 16)
    cout<<"Stand";
    if (d == 2 && y == 15)
    cout<<"Stand";
    if (d == 2 && y == 14)
    cout<<"Stand";
    if (d == 2 && y == 13)
    cout<<"Stand";
    if (d == 2 && y == 12)
    cout<<"Hit";
    if (d == 2 && y == 11)
    cout<<"Double Down";
    if (d == 2 && y == 10)
    cout<<"Double Down";
    if (d == 2 && y == 9)
    cout<<"Hit";
    if (d == 2 && y == 8)
    cout<<"Hit";
    if (d == 2 && y == 7)
    cout<<"Hit";
    if (d == 2 && y == 6)
    cout<<"Hit";
    if (d == 2 && y == 5)
    cout<<"Hit";
    if (d == 3 && y == 21)
    cout<<"Stand";
    if (d == 3 && y == 20)
    cout<<"Stand";
    if (d == 3 && y == 19)
    cout<<"Stand";
    if (d == 3 && y ==18)
    cout<<"Stand";
    if (d == 3 && y == 17)
    cout<<"Stand";
    if (d == 3 && y == 16)
    cout<<"Stand";
    if (d == 3 && y == 15)
    cout<<"Stand";
    if (d == 3 && y == 14)
    cout<<"Stand";
    if (d == 3 && y == 13)
    cout<<"Stand";
    if (d == 3 && y == 12)
    cout<<"Hit";
    if (d == 3 && y == 11)
    cout<<"Double Down";
    if (d == 3 && y == 10)
    cout<<"Double Down";
    if (d == 3 && y == 9)
    cout<<"Double";
    if (d == 3 && y == 8)
    cout<<"Hit";
    if (d == 3 && y == 7)
    cout<<"Hit";
    if (d == 3 && y == 6)
    cout<<"Hit";
    if (d == 3 && y == 5)
    cout<<"Hit";
    if (d == 4 && y == 21)
    cout<<"Stand";
    if (d == 4 && y == 20)
    cout<<"Stand";
    if (d == 4 && y == 19)
    cout<<"Stand";
    if (d == 4 && y == 18)
    cout<<"Stand";
    if (d == 4 && y == 17)
    cout<<"Stand";
    if (d == 4 && y == 16)
    cout<<"Stand";
    if (d == 4 && y == 15)
    cout<<"Stand";
    if (d == 4 && y == 14)
    cout<<"Stand";
    if (d == 4 && y == 13)
    cout<<"Stand";
    if (d == 4 && y == 12)
    cout<<"Stand";
    if (d == 4 && y == 11)
    cout<<"Double Down";
    if (d == 4 && y == 10)
    cout<<"Double Down";
    if (d == 4 && y == 9)
    cout<<"Double Down";
    if (d == 4 && y == 8)
    cout<<"Hit";
    if (d == 4 && y == 7)
    cout<<"Hit";
    if (d == 4 && y == 6)
    cout<<"Hit";
    if (d == 4 && y == 5)
    cout<<"Hit";
    if (d == 5 && y == 21)
    cout<<"Stand";
    if (d == 5 && y == 20)
    cout<<"Stand";
    if (d == 5 && y == 19)
    cout<<"Stand";
    if (d == 5 && y == 18)
    cout<<"Stand";
    if (d == 5 && y == 17)
    cout<<"Stand";
    if (d == 5 && y == 16)
    cout<<"Stand";
    if (d == 5 && y == 15)
    cout<<"Stand";
    if (d == 5 && y == 14)
    cout<<"Stand";
    if (d == 5 && y == 13)
    cout<<"Stand";
    if (d == 5 && y == 12)
    cout<<"Stand";
    if (d == 5 && y == 11)
    cout<<"Double Down";
    if (d == 5 && y == 10)
    cout<<"Double Down";
    if (d == 5 && y == 9)
    cout<<"Double Down";
    if (d == 5 && y == 8)
    cout<<"Hit";
    if (d == 5 && y == 7)
    cout<<"Hit";
    if (d == 5 && y == 6)
    cout<<"Hit";
    if (d == 5 && y == 5)
    cout<<"Hit";
    if (d == 6 && y == 21)
    cout<<"Stand";
    if (d == 6 && y == 20)
    cout<<"Stand";
    if (d == 6 && y == 19)
    cout<<"Stand";
    if (d == 6 && y == 18)
    cout<<"Stand";
    if (d == 6 && y == 17)
    cout<<"Stand";
    if (d == 6 && y == 16)
    cout<<"Stand";
    if (d == 6 && y == 15)
    cout<<"Stand";
    if (d == 6 && y == 14)
    cout<<"Stand";
    if (d == 6 && y == 13)
    cout<<"Stand";
    if (d == 6 && y == 12)
    cout<<"Stand";
    if (d == 6 && y == 11)
    cout<<"Double Down";
    if (d == 6 && y == 10)
    cout<<"Double Down";
    if (d == 6 && y == 9)
    cout<<"Double Down";
    if (d == 6 && y == 8)
    cout<<"Hit";
    if (d == 6 && y == 7)
    cout<<"Hit";
    if (d == 6 && y == 6)
    cout<<"Hit";
    if (d == 6 && y == 5)
    cout<<"Hit";
    if (d == 7 && y == 21)
    cout<<"Stand";
    if (d == 7 && y == 20)
    cout<<"Stand";
    if (d == 7 && y == 19)
    cout<<"Stand";
    if (d == 7 && y == 18)
    cout<<"Stand";
    if (d == 7 && y == 17)
    cout<<"Stand";
    if (d == 7 && y == 16)
    cout<<"Stand";
    if (d == 7 && y == 15)
    cout<<"Hit";
    if (d == 7 && y == 14)
    cout<<"Hit";
    if (d == 7 && y == 13)
    cout<<"Hit";
    if (d == 7 && y == 12)
    cout<<"Hit";
    if (d == 7 && y == 11)
    cout<<"Double Down";
    if (d == 7 && y == 10)
    cout<<"Double Down";
    if (d == 7 && y == 9)
    cout<<"Hit";
    if (d == 7 && y == 8)
    cout<<"Hit";
    if (d == 7 && y == 7)
    cout<<"Hit";
    if (d == 7 && y == 6)
    cout<<"Hit";
    if (d == 7 && y == 5)
    cout<<"Hit";
    if (d == 8 && y == 21)
    cout<<"Stand";
    if (d == 8 && y == 20)
    cout<<"Stand";
    if (d == 8 && y == 19)
    cout<<"Stand";
    if (d == 8 && y == 18)
    cout<<"Stand";
    if (d == 8 && y == 17)
    cout<<"Stand";
    if (d == 8 && y == 16)
    cout<<"Stand";
    if (d == 8 && y == 15)
    cout<<"Hit";
    if (d == 8 && y == 14)
    cout<<"Hit";
    if (d == 8 && y == 13)
    cout<<"Hit";
    if (d == 8 && y == 12)
    cout<<"Hit";
    if (d == 8 && y == 11)
    cout<<"Double Down";
    if (d == 8 && y == 10)
    cout<<"Double Down";
    if (d == 8 && y == 9)
    cout<<"Hit";
    if (d == 8 && y == 8)
    cout<<"Hit";
    if (d == 8 && y == 7)
    cout<<"Hit";
    if (d == 8 && y == 6)
    cout<<"Hit";
    if (d == 8 && y == 5)
    cout<<"Hit";
    if (d == 9 && y == 21)
    cout<<"Stand";
    if (d == 9 && y == 20)
    cout<<"Stand";
    if (d == 9 && y == 19)
    cout<<"Stand";
    if (d == 9 && y == 18)
    cout<<"Stand";
    if (d == 9 && y == 17)
    cout<<"Stand";
    if (d == 9 && y == 16)
    cout<<"Stand";
    if (d == 9 && y == 15)
    cout<<"Hit";
    if (d == 9 && y == 14)
    cout<<"Hit";
    if (d == 9 && y == 13)
    cout<<"Hit";
    if (d == 9 && y == 12)
    cout<<"Hit";
    if (d == 9 && y == 11)
    cout<<"Double Down";
    if (d == 9 && y == 10)
    cout<<"Double Down";
    if (d == 9 && y == 9)
    cout<<"Hit";
    if (d == 9 && y == 8)
    cout<<"Hit";
    if (d == 9 && y == 7)
    cout<<"Hit";
    if (d == 9 && y == 6)
    cout<<"Hit";
    if (d == 9 && y == 5)
    cout<<"Hit";
    if (d == 10 && y == 21)
    cout<<"Stand";
    if (d == 10 && y == 20)
    cout<<"Stand";
    if (d == 10 && y == 19)
    cout<<"Stand";
    if (d == 10 && y == 18)
    cout<<"Stand";
    if (d == 10 && y == 17)
    cout<<"Stand";
    if (d == 10 && y == 16)
    cout<<"Stand";
    if (d == 10 && y == 15)
    cout<<"Hit";
    if (d == 10 && y == 14)
    cout<<"Hit";
    if (d == 10 && y == 13)
    cout<<"Hit";
    if (d == 10 && y == 12)
    cout<<"Hit";
    if (d == 10 && y == 11)
    cout<<"Double Down";
    if (d == 10 && y == 10)
    cout<<"Hit";
    if (d == 10 && y == 9)
    cout<<"Hit";
    if (d == 10 && y == 8)
    cout<<"Hit";
    if (d == 10 && y == 7)
    cout<<"Hit";
    if (d == 10 && y == 6)
    cout<<"Hit";
    if (d == 10 && y == 5)
    cout<<"Hit";
    if (d == 1 && y == 21)
    cout<<"Stand";
    if (d == 1 && y == 20)
    cout<<"Stand";
    if (d == 1 && y == 19)
    cout<<"Stand";
    if (d == 1 && y == 18)


second part next

    cout<<"Stand";
    if (d == 1 && y == 17)
    cout<<"Stand";
    if (d == 1 && y == 16)
    cout<<"Stand";
    if (d == 1 && y == 15)
    cout<<"Hit";
    if (d == 1 && y == 14)
    cout<<"Hit";
    if (d == 1 && y == 13)
    cout<<"Hit";
    if (d == 1 && y == 12)
    cout<<"Hit";
    if (d == 1 && y == 11)
    cout<<"Hit";
    if (d == 1 && y == 10)
    cout<<"Hit";
    if (d == 1 && y == 9)
    cout<<"Hit";
    if (d == 1 && y == 8)
    cout<<"Hit";
    if (d == 1 && y == 7)
    cout<<"Hit";
    if (d == 1 && y == 6)
    cout<<"Hit";
    if (d == 1 && y == 5)
    cout<<"Hit";
    if (d == 2 && y == 201)
    cout<<"Stand";
    if (d == 2 && y == 191)
    cout<<"Stand";
    if (d == 2 && y == 181)
    cout<<"Stand";
    if (d == 2 && y == 171)
    cout<<"Hit";
    if (d == 2 && y == 161)
    cout<<"Hit";
    if (d == 2 && y == 151)
    cout<<"Hit";
    if (d == 2 && y == 141)
    cout<<"Hit";
    if (d == 2 && y == 131)
    cout<<"Hit";
    if (d == 3 && y == 201)
    cout<<"Stand";
    if (d == 3 && y == 191)
    cout<<"Stand";
    if (d == 3 && y == 181)
    cout<<"Double";
    if (d == 3 && y == 171)
    cout<<"Double";
    if (d == 3 && y == 161)
    cout<<"Hit";
    if (d == 3 && y == 151)
    cout<<"Hit";
    if (d == 3 && y == 141)
    cout<<"Hit";
    if (d == 3 && y == 131)
    cout<<"Hit";
    if (d == 4 && y == 201)
    cout<<"Stand";
    if (d == 4 && y == 191)
    cout<<"Stand";
    if (d == 4 && y == 181)
    cout<<"Double";
    if (d == 4 && y == 171)
    cout<<"Double";
    if (d == 4 && y == 161)
    cout<<"Double";
    if (d == 4 && y == 151)
    cout<<"Double";
    if (d == 4 && y == 141)
    cout<<"Hit";
    if (d == 4 && y == 131)
    cout<<"Hit";
    if (d == 5 && y == 201)
    cout<<"Stand";
    if (d == 5 && y == 191)
    cout<<"Stand";
    if (d == 5 && y == 181)
    cout<<"Double";
    if (d == 5 && y == 171)
    cout<<"Double";
    if (d == 5 && y == 161)
    cout<<"Double";
    if (d == 5 && y == 151)
    cout<<"Double";
    if (d == 5 && y == 141)
    cout<<"Double";
    if (d == 5 && y == 131)
    cout<<"Double";
    if (d == 6 && y == 201)
    cout<<"Stand";
    if (d == 6 && y == 191)
    cout<<"Stand";
    if (d == 6 && y == 181)
    cout<<"Double";
    if (d == 6 && y == 171)
    cout<<"Double";
    if (d == 6 && y == 161)
    cout<<"Double";
    if (d == 6 && y == 151)
    cout<<"Double";
    if (d == 6 && y == 141)
    cout<<"Double";
    if (d == 6 && y == 131)
    cout<<"Double";
    if (d == 7 && y == 201)
    cout<<"Stand";
    if (d == 7 && y == 191)
    cout<<"Stand";
    if (d == 7 && y == 181)
    cout<<"Stand";
    if (d == 7 && y == 171)
    cout<<"Hit";
    if (d == 7 && y == 161)
    cout<<"Hit";
    if (d == 7 && y == 151)
    cout<<"Hit";
    if (d == 7 && y == 141)
    cout<<"Hit";
    if (d == 7 && y == 131)
    cout<<"Hit";
    if (d == 8 && y == 201)
    cout<<"Stand";
    if (d == 8 && y == 191)
    cout<<"Stand";
    if (d == 8 && y == 181)
    cout<<"Stand";
    if (d == 8 && y == 171)
    cout<<"Hit";
    if (d == 8 && y == 161)
    cout<<"Hit";
    if (d == 8 && y == 151)
    cout<<"Hit";
    if (d == 8 && y == 141)
    cout<<"Hit";
    if (d == 8 && y == 131)
    cout<<"Hit";
    if (d == 9 && y == 201)
    cout<<"Stand";
    if (d == 9 && y == 191)
    cout<<"Stand";
    if (d == 9 && y == 181)
    cout<<"Hit";
    if (d == 9 && y == 171)
    cout<<"Hit";
    if (d == 9 && y == 161)
    cout<<"Hit";
    if (d == 9 && y == 151)
    cout<<"Hit";
    if (d == 9 && y == 141)
    cout<<"Hit";
    if (d == 9 && y == 131)
    cout<<"Hit";
    if (d == 10 && y == 201)
    cout<<"Stand";
    if (d == 10 && y == 191)
    cout<<"Stand";
    if (d == 10 && y == 181)
    cout<<"Hit";
    if (d == 10 && y == 171)
    cout<<"Hit";
    if (d == 10 && y == 161)
    cout<<"Hit";
    if (d == 10 && y == 151)
    cout<<"Hit";
    if (d == 10 && y == 141)
    cout<<"Hit";
    if (d == 10 && y == 131)
    cout<<"Hit";
    if (d == 1 && y == 201)
    cout<<"Stand";
    if (d == 1 && y == 191)
    cout<<"Stand";
    if (d == 1 && y == 181)
    cout<<"Hit";
    if (d == 1 && y == 171)
    cout<<"Hit";
    if (d == 1 && y == 161)
    cout<<"Hit";
    if (d == 1 && y == 151)
    cout<<"Hit";
    if (d == 1 && y == 141)
    cout<<"Hit";
    if (d == 1 && y == 131)
    cout<<"Hit";
    if (d == 2 && y == 12)
    cout<<"Split";
    if (d == 2 && y == 102)
    cout<<"Stand";
    if (d == 2 && y == 92)
    cout<<"Split";
    if (d == 2 && y == 82)
    cout<<"Split";
    if (d == 2 && y == 72)
    cout<<"Split";
    if (d == 2 && y == 62)
    cout<<"Split";
    if (d == 2 && y == 52)
    cout<<"Double";
    if (d == 2 && y == 42)
    cout<<"Hit";
    if (d == 2 && y == 32)
    cout<<"Split";
    if (d == 2 && y == 22)
    cout<<"Split";
    if (d == 3 && y == 12)
    cout<<"Split";
    if (d == 3 && y == 102)
    cout<<"Stand";
    if (d == 3 && y == 92)
    cout<<"Split";
    if (d == 3 && y == 82)
    cout<<"Split";
    if (d == 3 && y == 72)
    cout<<"Split";
    if (d == 3 && y == 62)
    cout<<"Split";
    if (d == 3 && y == 52)
    cout<<"Double";
    if (d == 3 && y == 42)
    cout<<"Hit";
    if (d == 3 && y == 32)
    cout<<"Split";
    if (d == 3 && y == 22)
    cout<<"Split";
    if (d == 4 && y == 12)
    cout<<"Split";
    if (d == 4 && y == 102)
    cout<<"Stand";
    if (d == 4 && y == 92)
    cout<<"Split";
    if (d == 4 && y == 82)
    cout<<"Split";
    if (d == 4 && y == 72)
    cout<<"Split";
    if (d == 4 && y == 62)
    cout<<"Split";
    if (d == 4 && y == 52)
    cout<<"Double";
    if (d == 4 && y == 42)
    cout<<"Hit";
    if (d == 4 && y == 32)
    cout<<"Split";
    if (d == 4 && y == 22)
    cout<<"Split";
    if (d == 5 && y == 12)
    cout<<"Split";

    if (d == 5 && y == 102)
    cout<<"Stand";
   if (d == 5 && y == 92)
    cout<<"Split";
    if (d == 5 && y == 82)
    cout<<"Split";
    if (d == 5 && y == 72)
    cout<<"Split";
    if (d == 5 && y == 62)
    cout<<"Split";
    if (d == 5 && y == 52)
    cout<<"Double";
    if (d == 5 && y == 42)
    cout<<"Split";
    if (d == 5 && y == 32)
    cout<<"Split";
    if (d == 5 && y == 22)
    cout<<"Split";
    if (d == 6 && y == 12)
    cout<<"Split";
    if (d == 6 && y == 102)
    cout<<"Stand";
    if (d == 6 && y == 92)
    cout<<"Split";
    if (d == 6 && y == 82)
    cout<<"Split";
    if (d == 6 && y == 72)
    cout<<"Split";
    if (d == 6 && y == 62)
    cout<<"Split";
    if (d == 6 && y == 52)
    cout<<"Double";
    if (d == 6 && y == 42)
    cout<<"Split";
    if (d == 6 && y == 32)
    cout<<"Split";
    if (d == 6 && y == 22)
    cout<<"Split";
    if (d == 7 && y == 12)
    cout<<"Split";
    if (d == 7 && y == 102)
    cout<<"Stand";
    if (d == 7 && y == 92)
    cout<<"Stand";
    if (d == 7 && y == 82)
    cout<<"Split";
    if (d == 7 && y == 72)
    cout<<"Split";
    if (d == 7 && y == 62)
    cout<<"Hit";
    if (d == 7 && y == 52)
    cout<<"Double";
    if (d == 7 && y == 42)
    cout<<"Hit";
    if (d == 7 && y == 32)
    cout<<"Split";
    if (d == 7 && y == 22)
    cout<<"Split";
    if (d == 8 && y == 12)
    cout<<"Split";
    if (d == 8 && y == 102)
    cout<<"Stand";
    if (d == 8 && y == 92)
    cout<<"Split";
    if (d == 8 && y == 82)
    cout<<"Split";
    if (d == 8 && y == 72)
    cout<<"Hit";
    if (d == 8 && y == 62)
    cout<<"Hit";
    if (d == 8 && y == 52)
    cout<<"Double";
    if (d == 8 && y == 42)
    cout<<"Hit";
    if (d == 8 && y == 32)
    cout<<"Hit";
    if (d == 8 && y == 22)
    cout<<"Hit";
    if (d == 9 && y == 12)
    cout<<"Split";
    if (d == 9 && y == 102)
    cout<<"Stand";
    if (d == 9 && y == 92)
    cout<<"Split";
    if (d == 9 && y == 82)
    cout<<"Split";
    if (d == 9 && y == 72)
    cout<<"Hit";
    if (d == 9 && y == 62)
    cout<<"Hit";
    if (d == 9 && y == 52)
    cout<<"Double";
    if (d == 9 && y == 42)
    cout<<"Hit";
    if (d == 9 && y == 32)
    cout<<"Hit";
    if (d == 9 && y == 22)
    cout<<"Hit";
    if (d == 10 && y == 12)
    cout<<"Split";
    if (d == 10 && y == 102)
    cout<<"Stand";
    if (d == 10 && y == 92)
    cout<<"Stand";
    if (d == 10 && y == 82)
    cout<<"Split";
    if (d == 10 && y == 72)
    cout<<"Hit";
    if (d == 10 && y == 62)
    cout<<"Hit";
    if (d == 10 && y == 52)
    cout<<"Hit";
    if (d == 10 && y == 42)
    cout<<"Hit";
    if (d == 10 && y == 32)
    cout<<"Hit";
    if (d == 10 && y == 22)
    cout<<"Hit";
    if (d == 1 && y == 12)
    cout<<"Split";
    if (d == 1 && y == 102)
    cout<<"Stand";
    if (d == 1 && y == 92)
    cout<<"Stand";
    if (d == 1 && y == 82)
    cout<<"Split";
    if (d == 1 && y == 72)
    cout<<"Hit";
    if (d == 1 && y == 62)
    cout<<"Hit";
    if (d == 1 && y == 52)
    cout<<"Hit";
    if (d == 1 && y == 42)
    cout<<"Hit";
    if (d == 1 && y == 32)
    cout<<"Hit";
    if (d == 1 && y == 22)
    cout<<"Hit";
    return 1;
} 




here is the last part
Last edited on
but it does not work


How does it not work? You need to be more descriptive.

Also, you could probably simplify that a lot by using some > or < comparisons as well.
I do not know why it does not work, and where can I learn more about these > or < comparisons?
I do not know why it does not work


I don't want why (I assume you don't know why, that's why you are asking :P). What is supposed to happen? What happens instead?

where can I learn more about these > or < comparisons?


cplusplus.com/doc/tutorial/operators/

See relational operators.
Also I (and I think most people) would say you have too many if cases. Writing so many cases is generally bad practice because, among other things, it is error prone, hard to read and so it's hard to find and fix bugs.

Could give the logic of the game i.e. how the game is meant to be played and the expected results, then we can find what's wrong with it.
The program is supposed to accept two numbers the user gives it, and then use those two numbers to tell the user wweather they should hold, split, double down, or hit.
The two numbers are the players hand in blackjack, and the dealers up card in blackjack
closed account (o3hC5Di1)
Hi there,

Please first simplify your code as firedraco suggested, for us to debug this is just too tedious.

An example of what firedraco means is this:

1
2
3
4
if ( (x < 6 && y < 16) || (x<17 && y < 112) )
{
    std::cout << "Stand" ;
}


Notice the ||, which is a logical or.
By using smaller than / greater than and or smartly, you can probably greatly reduce your amount of code.

All the best,
NwN
Is the code not working because i do nto have

{
std::cout << "Stand" ;
}


but i just have

cout<<"Stand";

instead of the { } and the std::
I have revised the code so it is shorted, it compiles, but it does not work, after I input the numbers it shuts down withoug giving me the answer.

#include <iostream>

using namespace std;

int d;
int y;


int main()
{
    cout<<"Hello! My name is BrandtBot, Please enter the Dealer's First Card\nDo not use faces, enter them as 10\nTo enter an ace, enter 1";
    cin>> d; 
    cin.ignore(); 
    cout<<"Please enter your hand as a number.\nIf you have a soft hand, enter a 1 after the number\nFor example, a soft 20 is 201.\nIf you have a pair, enter a 2 after the number that represents the card\nFor example a pair of aces would be 12"; 
    cin>> y; 
    cin.ignore(); 
    cin.get(); 
    if (d == 2 && y >= 13)
    cout<<"Stand";
    if (d == 2 && y == 12)
    cout<<"Hit";
    if (d == 2 && y == 11)
    cout<<"Double Down";
    if (d == 2 && y == 10)
    cout<<"Double Down";
    if (d == 2 && y <= 9)
    cout<<"Hit";
    if (d == 3 && y >= 13)
    cout<<"Stand";
    if (d == 3 && y == 12)
    cout<<"Hit";
    if (d == 3 && y == 11)
    cout<<"Double Down";
    if (d == 3 && y == 10)
    cout<<"Double Down";
    if (d == 3 && y == 9)
    cout<<"Double";
    if (d == 3 && y <= 8)
    cout<<"Hit";
    if (d == 4 && y >= 12)
    cout<<"Stand";
    if (d == 4 && y == 11)
    cout<<"Double Down";
    if (d == 4 && y == 10)
    cout<<"Double Down";
    if (d == 4 && y == 9)
    cout<<"Double Down";
    if (d == 4 && y <= 8)
    cout<<"Hit";
    if (d == 5 && y >= 12)
    cout<<"Stand";
    if (d == 5 && y == 11)
    cout<<"Double Down";
    if (d == 5 && y == 10)
    cout<<"Double Down";
    if (d == 5 && y == 9)
    cout<<"Double Down";
    if (d == 5 && y <= 8)
    cout<<"Hit";
    if (d == 6 && y >= 12)
    cout<<"Stand";
    if (d == 6 && y == 11)
    cout<<"Double Down";
    if (d == 6 && y == 10)
    cout<<"Double Down";
    if (d == 6 && y == 9)
    cout<<"Double Down";
    if (d == 6 && y <= 8)
    cout<<"Hit";
    if (d == 7 && y >= 16)
    cout<<"Stand";
    if (d == 7 && y == 15)
    cout<<"Hit";
    if (d == 7 && y == 14)
    cout<<"Hit";
    if (d == 7 && y == 13)
    cout<<"Hit";
    if (d == 7 && y == 12)
    cout<<"Hit";
    if (d == 7 && y == 11)
    cout<<"Double Down";
    if (d == 7 && y == 10)
    cout<<"Double Down";
    if (d == 7 && y <= 9)
    cout<<"Hit";
    if (d == 8 && y >= 16)
    cout<<"Stand";
    if (d == 8 && y == 15)
    cout<<"Hit";
    if (d == 8 && y == 14)
    cout<<"Hit";
    if (d == 8 && y == 13)
    cout<<"Hit";
    if (d == 8 && y == 12)
    cout<<"Hit";
    if (d == 8 && y == 11)
    cout<<"Double Down";
    if (d == 8 && y == 10)
    cout<<"Double Down";
    if (d == 8 && y <= 9)
    cout<<"Hit";
    if (d == 9 && y >= 16)
    cout<<"Stand";
    if (d == 9 && y == 15)
    cout<<"Hit";
    if (d == 9 && y == 14)
    cout<<"Hit";
    if (d == 9 && y == 13)
    cout<<"Hit";
    if (d == 9 && y == 12)
    cout<<"Hit";
    if (d == 9 && y == 11)
    cout<<"Double Down";
    if (d == 9 && y == 10)
    cout<<"Double Down";
    if (d == 9 && y <= 9)
    cout<<"Hit";
    if (d == 10 && y >= 16)
    cout<<"Stand";
    if (d == 10 && y == 15)
    cout<<"Hit";
    if (d == 10 && y == 14)
    cout<<"Hit";
    if (d == 10 && y == 13)
    cout<<"Hit";
    if (d == 10 && y == 12)
    cout<<"Hit";
    if (d == 10 && y == 11)
    cout<<"Double Down";
    if (d == 10 && y <= 10)
    cout<<"Hit";
    if (d == 1 && y >= 16)
    cout<<"Stand";
    if (d == 1 && y <= 15)
    cout<<"Hit";
    if (d == 2 && y >= 181)
    cout<<"Stand";
    if (d == 2 && y <= 171)
    cout<<"Hit";
    if (d == 3 && y >= 191)
    cout<<"Stand";
    if (d == 3 && y == 181)
    cout<<"Double";
    if (d == 3 && y == 171)
    cout<<"Double";
    if (d == 3 && y <= 161)
    cout<<"Hit";
    if (d == 4 && y >= 191)
    cout<<"Stand";
    if (d == 4 && y == 181)
    cout<<"Double";
    if (d == 4 && y == 171)
    cout<<"Double";
    if (d == 4 && y == 161)
    cout<<"Double";
    if (d == 4 && y == 151)
    cout<<"Double";
    if (d == 4 && y <= 141)
    cout<<"Hit";
    if (d == 5 && y >= 191)
    cout<<"Stand";
    if (d == 5 && y <= 181)
    cout<<"Double";
    if (d == 6 && y >= 191)
    cout<<"Stand";
    if (d == 6 && y <= 181)
    cout<<"Double";
    if (d == 7 && y >= 181)
    cout<<"Stand";
    if (d == 7 && y <= 171)
    cout<<"Hit";
    if (d == 8 && y >= 181)
    cout<<"Stand";
    if (d == 8 && y <= 171)
    cout<<"Hit";
    if (d == 9 && y >= 191)
    cout<<"Stand";
    if (d == 9 && y <= 181)
    cout<<"Hit";
    if (d == 10 && y >= 191)
    cout<<"Stand";
    if (d == 10 && y <= 181)
    cout<<"Hit";
    if (d == 1 && y >= 191)
    cout<<"Stand";
    if (d == 1 && y <= 181)
    cout<<"Hit";

    if (d == 2 && y == 12)
    cout<<"Split";
    if (d == 2 && y == 102)
    cout<<"Stand";
    if (d == 2 && y == 92)
    cout<<"Split";
    if (d == 2 && y == 82)
    cout<<"Split";
    if (d == 2 && y == 72)
    cout<<"Split";
    if (d == 2 && y == 62)
    cout<<"Split";
    if (d == 2 && y == 52)
    cout<<"Double";
    if (d == 2 && y == 42)
    cout<<"Hit";
    if (d == 2 && y <= 32)
    cout<<"Split";
    if (d == 3 && y == 12)
    cout<<"Split";
    if (d == 3 && y == 102)
    cout<<"Stand";
    if (d == 3 && y == 92)
    cout<<"Split";
    if (d == 3 && y == 82)
    cout<<"Split";
    if (d == 3 && y == 72)
    cout<<"Split";
    if (d == 3 && y == 62)
    cout<<"Split";
    if (d == 3 && y == 52)
    cout<<"Double";
    if (d == 3 && y == 42)
    cout<<"Hit";
    if (d == 3 && y <= 32)
    cout<<"Split";
    if (d == 4 && y == 12)
    cout<<"Split";
    if (d == 4 && y == 102)
    cout<<"Stand";
    if (d == 4 && y == 92)
    cout<<"Split";
    if (d == 4 && y == 82)
    cout<<"Split";
    if (d == 4 && y == 72)
    cout<<"Split";
    if (d == 4 && y == 62)
    cout<<"Split";
    if (d == 4 && y == 52)
    cout<<"Double";
    if (d == 4 && y == 42)
    cout<<"Hit";
    if (d == 4 && y <= 32)
    cout<<"Split";
    if (d == 5 && y == 12)
    cout<<"Split";
    if (d == 5 && y == 102)
    cout<<"Stand";
    if (d == 5 && y == 92)
    cout<<"Split";
    if (d == 5 && y == 82)
    cout<<"Split";
    if (d == 5 && y == 72)
    cout<<"Split";
    if (d == 5 && y == 62)
    cout<<"Split";
    if (d == 5 && y == 52)
    cout<<"Double";
    if (d == 5 && y <= 42)
    cout<<"Split";
    if (d == 6 && y == 12)
    cout<<"Split";
    if (d == 6 && y == 102)
    cout<<"Stand";
    if (d == 6 && y == 92)
    cout<<"Split";
    if (d == 6 && y == 82)
    cout<<"Split";
    if (d == 6 && y == 72)
    cout<<"Split";
    if (d == 6 && y == 62)
    cout<<"Split";
    if (d == 6 && y == 52)
    cout<<"Double";
    if (d == 6 && y <= 42)
    cout<<"Split";
    if (d == 7 && y == 12)
    cout<<"Split";
    if (d == 7 && y == 102)
    cout<<"Stand";
    if (d == 7 && y == 92)
    cout<<"Stand";
    if (d == 7 && y == 82)
    cout<<"Split";
    if (d == 7 && y == 72)
    cout<<"Split";
    if (d == 7 && y == 62)
    cout<<"Hit";
    if (d == 7 && y == 52)
    cout<<"Double";
    if (d == 7 && y == 42)
    cout<<"Hit";
    if (d == 7 && y == 32)
    cout<<"Split";
    if (d == 7 && y == 22)
    cout<<"Split";
    if (d == 8 && y == 12)
    cout<<"Split";
    if (d == 8 && y == 102)
    cout<<"Stand";
    if (d == 8 && y == 92)
    cout<<"Split";
    if (d == 8 && y == 82)
    cout<<"Split";
    if (d == 8 && y == 72)
    cout<<"Hit";
    if (d == 8 && y == 62)
    cout<<"Hit";
    if (d == 8 && y == 52)
    cout<<"Double";
    if (d == 8 && y <= 42)
    cout<<"Hit";
    if (d == 9 && y == 12)
    cout<<"Split";
    if (d == 9 && y == 102)
    cout<<"Stand";
    if (d == 9 && y == 92)
    cout<<"Split";
    if (d == 9 && y == 82)
    cout<<"Split";
    if (d == 9 && y == 72)
    cout<<"Hit";
    if (d == 9 && y == 62)
    cout<<"Hit";
    if (d == 9 && y == 52)
    cout<<"Double";
    if (d == 9 && y <= 42)
    cout<<"Hit";
    if (d == 10 && y == 12)
    cout<<"Split";
    if (d == 10 && y >= 92)
    cout<<"Stand";
    if (d == 10 && y == 82)
    cout<<"Split";
    if (d == 10 && y <= 72)
    cout<<"Hit";
    if (d == 1 && y == 12)
    cout<<"Split";
    if (d == 1 && y >= 92)
    cout<<"Stand";
    if (d == 1 && y == 82)
    cout<<"Split";
    if (d == 1 && y <= 72)
    cout<<"Hit";
    return 1;
} 
closed account (o3hC5Di1)
Hi there,

We didn't ask you to get the code shortened to make it work, we asked because this is rather impossible to analyse without too much hassle.

Here's a concrete example of code that can be shortened, it's a small example, but can be applied on a large scale in your program:

1
2
3
4
if (d == 3 && y == 11)
    cout<<"Double Down";
    if (d == 3 && y == 10)
    cout<<"Double Down";


You could write:

1
2
if (d == 3 && (y == 11 || y == 10) ) 
cout << "Double Down"; 


As I said, this is small scale, but if you really put some thought into this you can really shorten your code significantly.

All the best,
NwN
OK I have revised my code using ||'s, it compiles, but when I run it, it
allows me to insert my numbers, then it shuts itself down. here is the
revised code.

#include <iostream>

using namespace std;

int d;
int y;


int main()
{
    cout<<"Hello! My name is BrandtBot, Please enter the Dealer's First Card\nDo not use faces, enter them as 10\nTo enter an ace, enter 1";
    cin>> d; 
    cin.ignore(); 
    cout<<"Please enter your hand as a number.\nIf you have a soft hand, enter a 1 after the number\nFor example, a soft 20 is 201.\nIf you have a pair, enter a 2 after the number that represents the card\nFor example a pair of aces would be 12"; 
    cin>> y; 
    cin.ignore(); 
    cin.get(); 
    if (d == 2 && y >= 13)
    cout<<"Stand";
    if (d == 2 && y == 11 || y == 10)
    cout<<"Double Down";
    if (d == 2 && y <= 9 || y == 12)
    cout<<"Hit";
    if (d == 3 && y >= 13)
    cout<<"Stand";
    if (d == 3 && y == 11 || y == 10 || y == 9)
    cout<<"Double Down";
    if (d == 3 && y <= 8 || y == 12)
    cout<<"Hit";
    if (d == 4 && y >= 12)
    cout<<"Stand";
    if (d == 4 && y == 11 || y == 10 || y == 11 || y == 9)
    cout<<"Double Down";
    if (d == 4 && y <= 8)
    cout<<"Hit";
    if (d == 5 && y >= 12)
    cout<<"Stand";
    if (d == 5 && y == 11 || y == 10 || y == 9)
    cout<<"Double Down";
    if (d == 5 && y <= 8)
    cout<<"Hit";
    if (d == 6 && y >= 12)
    cout<<"Stand";
    if (d == 6 && y == 11 || y == 10 || y == 9)
    cout<<"Double Down";
    if (d == 6 && y <= 8)
    cout<<"Hit";
    if (d == 7 && y >= 16)
    cout<<"Stand";
    if (d == 7 && y == 11 || y == 10)
    cout<<"Double Down";
    if (d == 7 && y <= 9 || y == 15 || y == 14 || y == 13 || y == 12)
    cout<<"Hit";
    if (d == 8 && y >= 16)
    cout<<"Stand";
    if (d == 8 && y == 15 || y == 14 || y == 13 || y == 12 || y <= 9)
    cout<<"Hit";
    if (d == 8 && y == 11 || y == 10)
    cout<<"Double Down";
    if (d == 9 && y >= 16)
    cout<<"Stand";
    if (d == 9 && y == 15 || y == 14 || y == 13 || y == 12 || y <= 9)
    cout<<"Hit";
    if (d == 9 && y == 11 || y == 10)
    cout<<"Double Down";
    if (d == 10 && y >= 16)
    cout<<"Stand";
    if (d == 10 && y == 15 || y == 14 || y == 13 || y == 12 || y <= 10)
    cout<<"Hit";
    if (d == 10 && y == 11)
    cout<<"Double Down";
    if (d == 1 && y >= 16)
    cout<<"Stand";
    if (d == 1 && y <= 15)
    cout<<"Hit";
    if (d == 2 && y >= 181)
    cout<<"Stand";
    if (d == 2 && y <= 171)
    cout<<"Hit";
    if (d == 3 && y >= 191)
    cout<<"Stand";
    if (d == 3 && y == 181 || y == 171)
    cout<<"Double";
    if (d == 3 && y <= 161)
    cout<<"Hit";
    if (d == 4 && y >= 191)
    cout<<"Stand";
    if (d == 4 && y == 181 || y == 171 || y == 161 || y == 151)
    cout<<"Double";
    if (d == 4 && y <= 141)
    cout<<"Hit";
    if (d == 5 && y >= 191)
    cout<<"Stand";
    if (d == 5 && y <= 181)
    cout<<"Double";
    if (d == 6 && y >= 191)
    cout<<"Stand";
    if (d == 6 && y <= 181)
    cout<<"Double";
    if (d == 7 && y >= 181)
    cout<<"Stand";
    if (d == 7 && y <= 171)
    cout<<"Hit";
    if (d == 8 && y >= 181)
    cout<<"Stand";
    if (d == 8 && y <= 171)
    cout<<"Hit";
    if (d == 9 && y >= 191)
    cout<<"Stand";
    if (d == 9 && y <= 181)
    cout<<"Hit";
    if (d == 10 && y >= 191)
    cout<<"Stand";
    if (d == 10 && y <= 181)
    cout<<"Hit";
    if (d == 1 && y >= 191)
    cout<<"Stand";
    if (d == 1 && y <= 181)
    cout<<"Hit";
    if (d == 2 && y == 12 || y == 92 || y == 82 || y == 72 || y == 62 || y <= 32)
    cout<<"Split";
    if (d == 2 && y == 102)
    cout<<"Stand";
    if (d == 2 && y == 52)
    cout<<"Double";
    if (d == 2 && y == 42)
    cout<<"Hit";
    if (d == 3 && y == 102)
    cout<<"Stand";
    if (d == 3 && y == 52)
    cout<<"Double";
    if (d == 3 && y == 42)
    cout<<"Hit";
    if (d == 3 && y <= 32 || y == 12 || y == 92 || y == 82 || y == 72 || y == 62)
    cout<<"Split";
    if (d == 4 && y == 102)
    cout<<"Stand";
    if (d == 4 && y == 52)
    cout<<"Double";
    if (d == 4 && y == 42)
    cout<<"Hit";
    if (d == 4 && y <= 32 || y == 12 || y == 92 || y == 82 || y == 72 || y == 62)
    cout<<"Split";
    if (d == 5 && y == 102)
    cout<<"Stand";
    if (d == 5 && y == 52)
    cout<<"Double";
    if (d == 5 && y <= 42 || y == 12 || y == 92 || y == 82 || y == 72 || y == 62)
    cout<<"Split";
    if (d == 6 && y == 102)
    cout<<"Stand";
    if (d == 6 && y == 52)
    cout<<"Double";
    if (d == 6 && y <= 42 || y == 12 || y == 92 || y == 82 || y == 72 || y == 62)
    cout<<"Split";
    if (d == 7 && y == 12 || y == 82 || y == 72 || y ==32 || y == 22)
    cout<<"Split";
    if (d == 7 && y == 102 || y == 92)
    cout<<"Stand";
    if (d == 7 && y == 62 || y == 42)
    cout<<"Hit";
    if (d == 7 && y == 52)
    cout<<"Double";
    if (d == 8 && y == 12 || y == 92 || y == 82)
    cout<<"Split";
    if (d == 8 && y == 102)
    cout<<"Stand";
    if (d == 8 && y == 72 || y == 62 || y == 42)
    cout<<"Hit";
    if (d == 8 && y == 52)
    cout<<"Double";
    if (d == 9 && y == 12 || y == 92 || y == 82)
    cout<<"Split";
    if (d == 9 && y == 102)
    cout<<"Stand";
    if (d == 9 && y == 72 || y == 62 || y == 42)
    cout<<"Hit";
    if (d == 9 && y == 52)
    cout<<"Double";
    if (d == 10 && y == 12 || y == 82)
    cout<<"Split";
    if (d == 10 && y == 102 || y == 92)
    cout<<"Stand";
    if (d == 10 && y == 72 || y == 62 || y == 52 || y == 42 || y == 32 || y == 22)
    cout<<"Hit";
    if (d == 1 && y == 12 || y == 82)
    cout<<"Split";
    if (d == 1 && y == 102 || y == 92)
    cout<<"Stand";
    if (d == 1 && y == 72 || y == 62 || y == 52 || y == 42 || y == 32 || y == 22)
    cout<<"Hit";
    return 1;
} 

The hell man, use switch/case, I can't understand anything!


Notice how your program will print Stand, Split and Hit for the same set of input.

1
2
3
4
5
6
7
8
9
10
11
    if (d == 2 && y >= 13)
        cout<<"Stand";
...
    if (d == 2 && (y == 12 || y == 92 || y == 82 || y == 72 || y == 62 || y <= 32))
        cout<<"Split";
...
    if (d == 2 && y == 102)
        cout<<"Stand";
...
    if (d == 2 && y <= 171)
        cout<<"Hit";


if d=2, and y=102, your program will print

StandSplitStandHit

Maybe you mean to use else if



Last edited on
ess- what do you mean?

iseeplusplus- what is teh diffrence between my code and the one you put up?

and incase someone else is reading this,

the code compiles, but it does not work, after I input
the numbers it shuts down without
giving me the answer.

the code compiles, but it does not work, after I input
the numbers it shuts down without
giving me the answer.


Check out the sticky at the top of this forum entitled "Console closing down".
Last edited on
Pages: 12