+ 2

Need help with C++ code.(Solved)

I'm working on a C++ program. Can't quite get it to work. (Solved) https://code.sololearn.com/cTib8yl2T23k/#cpp

26th Jan 2018, 11:28 PM
Ch Pe
Ch Pe - avatar
11 Answers
+ 8
The problem is at line 47 loop for, you have: for(int i=total; i<22; i++) {code} The loop for should be like this: for(int i=total; i<21; i++) {code} Mate... That's pretty fun game. Though i don't understand why you have for loops that just executes one loop, or why if the user don't want to play anymore, the program still throw a card(shouldn't it end?). Hope it's what you need, comment if it is.
26th Jan 2018, 7:09 AM
Fabio
+ 5
Well. What you need to do is at line 52 condition if: if(goAgain == 'n') { cout << "Want to play again?"<<endl; cin >> playAgain2; break; }
26th Jan 2018, 4:16 PM
Fabio
+ 4
There is another way...
26th Jan 2018, 9:25 PM
Fabio
+ 4
You can equal the for loop counter to its last value, so the loop will end. For example: for(int i=0;i<21;i++){ if(goAgain=='n') { i = 21; } } In this case the loop will execute until that.
26th Jan 2018, 10:27 PM
Fabio
+ 3
My next question is "When the user says they don't want to go again, meaning they don't want another card, i want the loops to stop and end the game and ask if the user wants to play again. I tried having while(goAgain != 'n) in the while loops. Trying in "n doesn't stop the loops.
26th Jan 2018, 9:29 AM
Ch Pe
Ch Pe - avatar
+ 2
@Fabio changing to for(int i=total; i<21; i++) {code}helped. Logic / math error.
26th Jan 2018, 8:59 AM
Ch Pe
Ch Pe - avatar
+ 2
@Fabio for this assignment im not allowed to use break, return, exit, but at this point im just going to say f*** it, use break and submit it. Not being able to use anything other than input, output and loops is silly and I've spent too much time on this already.
26th Jan 2018, 9:23 PM
Ch Pe
Ch Pe - avatar
+ 2
I'm thinking about trying to figure out how to manually code a break statement without using actually typing break. Kind of like in Java you can make a Math.random method that works the same as the built in Math.random()
26th Jan 2018, 10:17 PM
Ch Pe
Ch Pe - avatar
+ 2
@Fabio. Brilliant. Why didn't i think of that?
26th Jan 2018, 10:51 PM
Ch Pe
Ch Pe - avatar
+ 2
Thanks!! 😀
26th Jan 2018, 10:57 PM
Fabio
+ 1
The problem is...Fill in the blanks to take the name and age of a user as input. name is a string, age is an integer. [ ]name; [int]age; I give char keyword to name but it result in wrong answer... What was the mistake I have done?
19th Jan 2024, 3:50 AM
mh Brijeesh
mh Brijeesh - avatar