Click here to Skip to main content
15,909,530 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
how do i write a simple program that does the following..
reads five numbers eg.12345
and displays them as follows
1
2
3
4
5
Posted

What have you done ?
Can you describe in words how to do this task ?

You are coding in c++, so have a look at the following things:

std::cin to input values.
std::cout to output values
std::vector to store the values read.
for to iterate the vector.
 
Share this answer
 
Comments
Mr. gomez 24-Feb-12 16:19pm    
read five numbers at once eg. enter numbers: 12345
the output should be as follows:
1
2
3
4
5
on five different lines
Maximilien 24-Feb-12 16:23pm    
Can you translate that into "pseudo-code" ?
Do you know the "equivalent" in c++ ?
how do you read numbers from the keyboard into a string ?
how do you iterate ( loop) the input string ?
how do you print out the individual number ?

Help us help you, do something, we'll not give you the whole code.
Max.
One way to achieve this task is

C#
int _tmain(int argc, _TCHAR* argv[])
{
    int number;
    scanf("%d",&number);

    char buf[10] = {0};
    itoa(number,buf,10);
    for(int count = 0; count < strlen(buf);count++)
        printf("%c\n",buf[count]);

    return 0;
}
 
Share this answer
 
Comments
Mr. gomez 24-Feb-12 16:35pm    
thanks, but this is C. i need help with C++
just make your loop from 1 to specific number(that you think will be the length eg 12345 in this particular case you will run loop five time) after that than in each iteration you have to get a remainder and put it in array than print the array in reverse order
 
Share this answer
 
Comments
Mr. gomez 23-Feb-12 14:48pm    
thanks for the insight ali, i also need some code to help me out.am just teaching myself c++

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