+ 1
doWhile in C
Hi guys, I'm beginner in C and im doing some exercise I create to experiment...I can't figure out what's worng in this code can someonr pls help? thank u guys and forgive my English #include studio.h int main();{ int firstCard; int secondCard; int booJack = 21; int result; do{ printf("What's your numbers? "); scanf("%d",&firstCard); scanf("%d",&secondCard); result = firstCard+secondCard; printf("Better luck next time!"); }while(result == booJack); printf("21!BOOJACK!\nYOU WIN!"); return 0;}
6 Antworten
+ 1
you might mean black jack mister ,
in Integer case 2 + 1 is 3 ,
in String case "2" + "1" is "21" , it can be "1" + "2" either become "12".
in your code you ask program to keep asking until total of sum are NOT 21 , in other word , while total sum of (15 + 6) or (10 + 11) or (8 + 13) or (so on) are 21 , it loops question.
it does run program once because you asking it to do something regardless , then check condition after input.
variable case.
try to find out about String concatenation.
+ 1
first, my I don't wear a cap on my head, second, main reason must be fix at declared line
+ 1
yes I want exit loop only of sum is 21
0
You want fix your code so that it can run, follow my previous post and see if it work
0
then try :
while ( result != 21 ){
};
//or
do{
}while( result != 21 );
instead.