Please help

Write a function that receives a positive integer and display each digit of such integer one digit per line. For example, if the integer the function receives 2475, then it should display the digits of this number as following:
5
7
4
2
What do these give you:
1
2
value % 10
value / 10


In a while ...
what you mean?
Ram1 you need to be careful of multiple posts asking the same question, i have already answered this for you in another thread.
If you want to print it out like that use an array

so i wont code it for you ill show you how

nameoffunc (array[4])

std:: array[]3
array[2]
array[1]
array[0]



main

arraytosend[]

nameofunc(arraytosend[])


now with you C++ knowledge turn this advice to C++ code
You don't need an array

1
2
3
4
5
6
7
8
9
10
void myFunc(int y)
{
    int x=log10(y)+1;
    for(int i=0;i<x;i++)
    {
        int a=y%10;
        y=(y-a)/10;
        cout<<a<<endl;
    }
}
I see,
Ram1 wrote:
I'm doing an exercises from my book, I need help with them to check my work.

Nobody can help you to check your work if you have not done any work to check.

You must write a function. Function must take an integer parameter. Function must print something. What should the function return?


What mean I? Lets rephrase:

If you have in code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int number = 47;

int foo = number % 10;
// What is the value of foo now?

int bar = number / 10;
// What is the value of bar now?


// Do you know this construct?
while ( condition )
  {
    // statements
  }
Topic archived. No new replies allowed.