Program is not giving output, why?
Its 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 31 32 33 34
|
#include <iostream>
using namespace std;
int main()
{
int n,r,c=0,p=0;
cin>>n;
r=n%10;
if(r>3)
{
while(r!=8)
{
c++;
r++;
}
}
else if(r<=3)
{
while(abs(r) != 8)
{
p++;
r--;
}
}
cout<<min(c,p)<<endl;
return 0;
}
|
Last edited on
Besides the output, look carefully at lines 14 and 22. What if n starts out at 9, 19, -9, -19, etc?
Topic archived. No new replies allowed.