1. ## [RESOLVED] C++ questions

Hello, I have the following homework exercies which I couldn't resolve, can anybody tell me how to do them, Thanks in advance..

QUESTION1

Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits, example ( if he entered 3456 then it should print 3 4 5 6 and also if he entered 23454566 etc).

QUESTION2

Write a program that prompts the user to input an intefer then outputs the number with the digits reversed as: 12345 ---> 54321 and also 400 --> 004.

Thanks for the help,
zeid  Reply With Quote

2. ## Re: C++ questions

Since this is a homework assignment I will not give you an actuall implementation.

Question1:
There are two ways to solve this, either read a number, and extract digits, etc.
But do you really need a number? In this case reading a string should be enough.

Question2:
Same thing, don't interpret this as a number question, but as a string question.

It may be the case that you are actually supposed to use numbers instead of strings, in that case the questions are worded incorrectly, because they also allow the (simpler) string implementation. In fact, reversing "400" to get "004" is only possible with strings, because as a number it would be just "4".  Reply With Quote

3. ## Re: C++ questions

thank u, but i'm completely new to c++ so can u please show me the code of doing it. or can anyone else help me with it..

Thanks again,
zeid  Reply With Quote

4. ## Re: C++ questions

You can use the modulo operator (%) to split numbers into their parts. Now grab your C++ textbook (you do have such a thing, right?) and solve the problem.

Because I'm in a good mood, here's some pseudo-code to do the first part of the first exercise.
Code:
```number = read number from user;
while(number > 0) {
digit = number % 10;
number = number / 10;

print digit;
}```  Reply With Quote

5. ## Re: C++ questions

Hi CornedBee,

Isn't what you wrote 'pseudo - pseudo code'? ChuckB  Reply With Quote

6. ## Re: C++ questions

There's no standard for pseudo-code. Mine always looks like this.  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•