doWhile in C | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 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;}

12th Sep 2017, 12:29 AM
dimitriDV
dimitriDV - avatar
5 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.
12th Sep 2017, 12:49 AM
Mikhael Anthony
Mikhael Anthony - avatar
+ 1
first, my I don't wear a cap on my head, second, main reason must be fix at declared line
12th Sep 2017, 12:36 AM
Nura Programmer
Nura Programmer - avatar
+ 1
yes I want exit loop only of sum is 21
12th Sep 2017, 12:46 AM
dimitriDV
dimitriDV - avatar
0
You want fix your code so that it can run, follow my previous post and see if it work
12th Sep 2017, 12:48 AM
Nura Programmer
Nura Programmer - avatar
0
then try : while ( result != 21 ){ }; //or do{ }while( result != 21 ); instead.
12th Sep 2017, 12:52 AM
Mikhael Anthony
Mikhael Anthony - avatar