+ 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
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.
+ 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;
}
+ 4
There is another way...
+ 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.
+ 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.
+ 2
@Fabio changing to for(int i=total; i<21; i++) {code}helped. Logic / math error.
+ 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.
+ 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()
+ 2
@Fabio. Brilliant. Why didn't i think of that?
+ 2
Thanks!! 😀
+ 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?