Question #48404

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.

Only positive integers are valid input. Negative integers as input should produce an error message. Use zero (0) as your sentinel value.

Expert's answer

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;

}

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;

}

## Comments

## Leave a comment