Why the program is not giving output?

I've written the following program..but it is only taking input into a loop but not giving any output. Why?

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
#include <iostream>

using namespace std;

int main()
{
    int n,c=0;
    cin>>n;

    int r=n%10;

    if(r>8)
    {
        while(r!=8)
        {
            c--;
        }
    }
    else if(r<8)
    {
        while(r!=8)
        {
             c++;
        }
    }

    cout<<c<<endl;

    return 0;
}
Your code has no way of exiting the while loops. the variable r is not being changed within the while loops so the statement r!=8 would be true all the time.
Topic archived. No new replies allowed.