Program executes correctly at first iteration only ! Why ?

Where have i gone wrong ?

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
#include<iostream.h>
#include<conio.h>
void main()
{
 int ch,x,n,d,sum=0;
 do
 {
 cout<<"\n\nEnter a number\n";
 cin>>n;
 x=n;
 do
  {
	d=n%10;
	sum=sum+(d*d*d);
	n=n/10;
  } while(n!=0);
  if(sum==x)
  cout<<"Number is Armstrong !\n";
  else
  cout<<"No, its not Armstrong number !\n";
  cout<<"Wanna continue ?\t";
  ch=getche();
  } while(ch=='y'||ch=='Y');

  getch();
}
Last edited on
1. Could you put that in code tags, because it really does help and makes it easier to read.

2. Generally, it is much better for you to tell us what is going wrong, because although we can work it out for ourselves with small programs, it makes it much quicker as we can quickly catch small, common mistakes.

Thanks (sorry about bombarding you with rules/regulations though they are there for a reason and they do help)
Last edited on
Also, your problem is:

1. Use iostream instead of iostream.h --- don't ask me why, I don't know, but I think iostream.h is depreciated or at least non standard anymore.

2. just underneath #include <iostream> put in:
using namespace std;

EDIT: Sorry, I didn't actually check the number output, I just assumed your problem was that it wasn't compiling. At least on my compiler, it wasn't compiling at all, then again, computers always stuff up for me ;)
Last edited on
Now, Fine ?

Now, Execute the program.......

At first iteration, 153 proves to be Armstrong....!

But, next.... Not even 1 is accepted as Armstrong !

That's not a problem.... I checked out !


EDIT: So, there's no one who could solve my problem ???????
That's what I fee !
:-( :'(
Last edited on
I'm trying...be patient...
Topic archived. No new replies allowed.