Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C++
#include<iostream.h>
void main()
{
  long umber=7583241;
  int first=0,secind=0;
  do
  {
    int r= number%10;
    if(r%2==0)
      first+=r;
    else
      second+=r;
    number/=10;
  } while (number>0)
  cout<<first-second;
}
Posted
Updated 22-Mar-15 4:46am
v3
Comments
phil.o 22-Mar-15 10:28am    
What is the issue? What is the question?

You should first fix the code, as it stands it wouldn't compile.

To get stepwise output, you have to, well, write the output at each step, e.g.

C++
do
  {
    int r= number % 10;
    if(r%2==0)
      first+=r;
    else
      second+=r;

   cout << "number: " << number << ", r: " << r << ", first: " << first << ", second: " << second << endl;
    number/=10;
  } while (number>0);
 
Share this answer
 
v2
Start by correcting the syntax errors:
1) You declare it as "umber" and use it as "number"
2) you declare it as "secind" and use it as "second"
3) You need a semicolon after the while condition.

Fix those, and it might compile. It might not work - but I have no idea what it is supposed to do, so I can't say at this stage. But until it compiles without errors, it won't run at all...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900