User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 397,770 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,531 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 1358 | Replies: 2
Reply
Join Date: Nov 2004
Posts: 11
Reputation: Extreme is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Extreme Extreme is offline Offline
Newbie Poster

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

  #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<<<
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2004
Posts: 3,462
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 16
Solved Threads: 138
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!!!

  #2  
Nov 29th, 2004
You forgot to update the loop counter.
while(n>0)
{
   x=n%10;
   sum+=x;
   n/=10;
}
Reply With Quote  
Join Date: Nov 2004
Posts: 11
Reputation: Extreme is an unknown quantity at this point 
Rep Power: 0
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!!!

  #3  
Nov 29th, 2004
hey Dave Sinkula thanx a lot...
>>>Extreme<<<
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C++ Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 4:25 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC