Can any1 tell me whatz wrong in this program...this does not show the output!!!

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2004
Posts: 12
Reputation: Extreme is an unknown quantity at this point 
Solved Threads: 0
Extreme Extreme is offline Offline
Newbie Poster

Can any1 tell me whatz wrong in this program...this does not show the output!!!

 
0
  #1
Nov 29th, 2004
Hey can any1 figure out wat is wrong in this program...after i compiled it and executed the program ....I inputed the value of n...but after that it does not show the output...Can any1 help me plz..!!

The program which I wrote is below::


#include<iostream.h>

int sumofdigits(int n)

{

int sum=0, x;

while(n>0)

{
x=n%10;

sum+=x;

}

return sum;

}

void main()

{

int n, sum;

cout<<"Enter any number"<<endl;

cin>>n;

sum=sumofdigits(n);

cout<<"Sum of digits ="<<sum;

cout<<endl;

}
>>>Extreme<<<
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,364
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 242
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Can any1 tell me whatz wrong in this program...this does not show the output!!!

 
0
  #2
Nov 29th, 2004
You forgot to update the loop counter.
while(n>0)
{
   x=n%10;
   sum+=x;
   n/=10;
}
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 12
Reputation: Extreme is an unknown quantity at this point 
Solved Threads: 0
Extreme Extreme is offline Offline
Newbie Poster

Re: Can any1 tell me whatz wrong in this program...this does not show the output!!!

 
0
  #3
Nov 29th, 2004
hey Dave Sinkula thanx a lot...
>>>Extreme<<<
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC