Why is my program crashing?

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?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  #include <iostream>
using namespace 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;
}
Line 30. Division by zero. See if you can step through the program and see why.
Topic archived. No new replies allowed.