944,008 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2070
  • C++ RSS
Nov 29th, 2004
0

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

Expand Post »
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;

}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Extreme is offline Offline
12 posts
since Nov 2004
Nov 29th, 2004
0

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

You forgot to update the loop counter.
while(n>0)
{
   x=n%10;
   sum+=x;
   n/=10;
}
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Nov 29th, 2004
0

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

hey Dave Sinkula thanx a lot...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Extreme is offline Offline
12 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Size
Next Thread in C++ Forum Timeline: Problems with switch statement





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC