Overwhelmed & Confused with homework...

This is my homework assignment
3.17 (Digit Extraction) Complete an application that allows the user to input a five-digit number. Your application should then separate the number into its individual digits and display on a separate line each digit.

1. Define a variable to store user input, including appropriate comments.

2. Prompting the user for and storing a number. Prompt the user for a number and use cin to place the value in the variable you defined in the preceding step.

3. Display each digit separately. [Hint: You can use the % operator to extract the ones digit from a number. For instance, 12345 % 10 is 5. You can use division (/) to peel off digits from a number. For instance, 12345 / 10 is 1234. This allows you to treat the 4 in 12345 as a ones digit. Now you can isolate the 4 by using the % operator. Apply this technique to the rest of the digits.]

4. Save, compile and run the completed application. Type 12345 at the Enter five-digit number: prompt. Ensure that the output appears as shown in Fig. 3.29 in your text.


I am so lost right now. Our last homework assignment wat the simple "Hello World" program, which I understood. Now, i'm completely lost.

I do not understand how to get started (Step 1), and if someone could help me you would save my day. Ive been trying various things for a couple hours and have nothing to show.

thanks
the finished product is supposed to look like this
http://img.photobucket.com/albums/v323/Monkeyman1010/homework.gif
Hmm maybe store each digit in an array of its own so you can then output the array in whatever order you want and with a new line?

Right just read the rest of the post :)

To help you out just read C++ variables part on the website. If that doesn't work I'll see what I can do to help.
Last edited on
#include <iostream>

using namespace std;

int main () {

int num ;
int rem ;

cout << " Input a 5 digit number : ";
cin >> num;;

for (int i = 0; i < 5; i++) {
rem = num %10;
num = num / 10;
cout << rem << endl;
}
return 0;
}
ok ceemor, that helped. I still need to have the text "Ones digit is :", "Tens digit is:" and so on..

I put that text as a cout statement, and it shows up ok, but the numbers appear underneath it instead of after the :
@ceeemor: Please don't post solutions. If you really want to help, then just point them in the right direction, instead of giving the full solution.

Edit:

@BrassMonkey1010: endl stands for end line. So if you write
1
2
cout<<"Hello"<<endl;
 cout<<"World";


It will print as

Hello World


Hope this helps !
Last edited on
Also, endl is approximately equal to this: std::cout << "\n" << std::flush;
If you don't need to flush the buffer, use "\n" instead of endl.
Topic archived. No new replies allowed.