simple programe

hay guys i have hw assignment to make a programe which will take a number and print it line wise at screen ..for example if i give 3121 then it will print
3
1
2
1
help me soooooooooon
Declare a variable, input. Do a cout, ask for the user to input a number. Then cin that to input. then cout them using endls.

Right? I'm not 100% sure
thats right ashley. But what if the user enters a number like 1234, technicly that will all be read into the input and when you cout the input it will be on one line. I think the best way would be to use a string input like this.

string input;

cout << "Enter a number....any size: ";
cin >> input;

for(int i = 0; i < input.length(); i++)
cout << input.at(i) << endl;

this is probably the easiest way, the other way would be to use mod statements, and the program wouldnt be that flexible. for instance if you were to enter this for a number

1237826783553272527362826422826227 and you had the data type to anything other than a string, you would not print out the correct stuff. that is a huge number, so i think string is best if you want a program that will work with just about any size number.

Easiest way would be using a string

Pseudo code:
ask user for input
recieve input
output each character in itself and add a new line


edit: It appears I've been beaten to the punch
Last edited on
lol, thats cool warnis. at least we think the same. I know it works with a string perfectly. It just doesnt seem right at first glance.... string and a number??? But yea, glad you think the same
I think your professor wants you to play with the division / and remainder % operators. Not strings.
Topic archived. No new replies allowed.