My program was basically made to prompt the user for a positive integer and tell the user whether the number is deficient, perfect, or abundant. It should continue until the user enters -1. But it crashes when it finishes the countdown. Any ideas?
#include <iostream>
usingnamespace std;
int main()
{
int input, sum, countdown;
cout << "Please enter any positive integer and I will tell you if it is deficient, perfect, or abundant.\n";
cout << "Once you are done, please enter a -1 to let me know you are done.\n";
do
{
sum = 0;
cin >> input;
if (input < 0 && input != -1)
{
cout << "I cannot accept negative integers. Enter another number.\n";
cin >> input;
}
if (input >= 0)
cout << "You have entered " << input << ".\n";
countdown = input;
while (input >= 0)
{
countdown = countdown - 1;
sum = sum + (input/countdown);
cout << "The countdown is " << countdown << " the sum is " << sum << endl;
}
if (sum > input && countdown == 0)
cout << "The number is abundant.\n";
if (sum == input && countdown == 0)
cout << "The number is perfect.\n";
if (sum < input && countdown == 0)
cout << "The number is deficient.\n";
sum = 0;
}
while(input >= 0);
if (input == -1)
cout << "You are finished entering numbers.\n";
system("pause");
return 0;
}