Write a program that prompts the user to enter a positive integer and then uses this criterion to determine whether the number is divisible by 11.
Only positive integers are valid input. Negative integers as input should produce an error message. Use zero (0) as your sentinel value.
using namespace std;
int main() {
int current_choice;
while(true) {
cout << "Enter and positive integer or zero to exit: ";
cin >> current_choice;
if (current_choice == 0) {
cout << "End of program.\n";
break;
}
if (current_choice < 0) {
cout << "Error! Please enter positive number or 0 to exit.\n";
}
if (current_choice > 0) {
if (current_choice % 11 == 0)
cout << "Your number is divisible by 11!\n";
else
cout << "Your number isn't divisible by 11!\n";
}
}
return 0;
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
C++