- #1
MMOne
- 3
- 0
Ask the user for a number between 1 and 11; stop asking when the user enters 0 OR when the total goes over 21. Display the total on the screen. For example:
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int num, total;
cout << "Enter a number between 1 and 11 (0 to stop): ";
cin >> num;
cout << num << endl;
while((num > 0)&&(num < 12)){
cout << num << endl;
total = total + num;
while ((num == 0) || (total > 21)){
cout << "Your total was " << total << endl;
cout << "Thanks for playing!" << endl;
}
}
return 0;
}
When I compile it will not provide the messages at the end. Not sure how to do this my code might just be sloppy. Any help would be appreciated.
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int num, total;
cout << "Enter a number between 1 and 11 (0 to stop): ";
cin >> num;
cout << num << endl;
while((num > 0)&&(num < 12)){
cout << num << endl;
total = total + num;
while ((num == 0) || (total > 21)){
cout << "Your total was " << total << endl;
cout << "Thanks for playing!" << endl;
}
}
return 0;
}
When I compile it will not provide the messages at the end. Not sure how to do this my code might just be sloppy. Any help would be appreciated.