Using C Write a program that continues to ask the user for a
Using C++:
Write a program that continues to ask the user for a number between one and eleven (inclusive) until the total of the numbers is greater than 21. Be sure to reject any number that is not between 1 and 11 (inclusive).
Solution
Solution.cpp
#include <iostream>//header file for input output function
using namespace std;//it tells the compiler to link std namespace
int main()
{//main function
int num,total=0;
do
{//do while loop
label:
cout<<\"please enter the number between 1 to 11 \";
cin>>num;//keyboard inputting
if(num<1 || num>11){
cout<<\"you have entered less than 1 or greater than 11 \ please enter the number between 1 to 11 \"<<endl;
goto label;
}
else
total=total+num;
}while(total<21);
cout<<\"total is \"<<total;
return 0;
}
output
please enter the number between 1 to 11 4
please enter the number between 1 to 11 5
please enter the number between 1 to 11 6
please enter the number between 1 to 11 99
you have entered less than 1 or greater than 11
please enter the number between 1 to 11
please enter the number between 1 to 11 -4
you have entered less than 1 or greater than 11
please enter the number between 1 to 11
please enter the number between 1 to 11 7
total is 22
