I'm trying to write a code which adds a value - say X - to a user entered int, and continues to allow the user to add further int values to 'X+all previously entered int values' until a value of 21 or greater is reached - where the code exits the loop. I thought it would be a simple case of value=value+X but I'm going wrong somewhere...
void additionFunction()
{
int j=0;
int tot;
//tot=cat.firstCard+cat.secondCard; is the actual tot value but for simplicity;
tot=5;
for(j=0; j+tot<22; j=j+tot)
{
printf("Enter next card\n");
scanf("%d",&j);
}
}
I know this is a very simple question but I'm stuck as to what else to try. It was originally implemented in a if,do,switch loop in the shortened form;
if(cat.firstCard!=11 && cat.secondCard!=11)
{
do
{
switch(tot+j>=4 && tot+j<=8)
{
printf("Hit\nEnter next card\n");
scanf("%d",&j);
break;
}
switch(tot+j==9 && (cat.dealersCard==2 || (cat.dealersCard>=7 && cat.dealersCard<=11)))
{
printf("Hit\nEnter next card\n");
scanf("%d",&j);
break;
}
...
switch(tot+j>=17 && tot+j<=21)
{
printf("Stand\n");
j=50;
break;
}
switch(tot+j>21)
{
printf("Bust\n");
j=50;
break;
}
}while(j!=50);
}
else //etc.
This method didn't work either. I know this is simple but I can't find the answer anywhere. It would be great if you could answer for the second case but any answer is appreciated!
only use stdio.h, no global variables
tot, notj, don't you? Or you need to read intototinstead ofj, but then the names, to the extent they are at all meaningful, are wrong. You really need to check the return value fromscanf()too, so you can spot that the user typed K (for King) instead of 9. - Jonathan Lefflerswitch:) - Unmanned Player