+ 2

Simple problem

Simple problem? Program reads two-digit number and prints every digit separately, separated by a space. Input One integer from 10 to 99 including. Output Two digits separated by Input example 23 Output example 2 3

13th Nov 2017, 5:09 PM
Chapay Gahramanov
Chapay Gahramanov - avatar
13 Réponses
+ 4
@Chapay I posted up code with your exact specifications that you asked for. It ensures the input is within the range, and it'll loop to obtain new input until the correct range is inputted. If input is within range, it'll print it separated by a whitespace. Just note, since it's SoloLearn compiler, it isn't going to prompt you for input again. As such, the loop will keep using the same input because of SoloLearn. However, in another compiler that isn't restricted, it'll work as intended. Hope it helps. Good luck to you in your learning.
13th Nov 2017, 5:37 PM
AgentSmith
+ 2
https://www.sololearn.com/Discuss/854652/simple-problem Give me a moment and I'll post my version of it, if you're simply just trying to get another take on the answer.
13th Nov 2017, 5:16 PM
AgentSmith
13th Nov 2017, 5:24 PM
Saurabh Tiwari
Saurabh Tiwari - avatar
+ 2
finally thank you very much
13th Nov 2017, 5:26 PM
Chapay Gahramanov
Chapay Gahramanov - avatar
+ 2
only one suggestion try on ur own for sometime if u still didn't get it don't bother to ask HAPPY CODING!!! AND WELCOME SL COMMUNITY!!!
13th Nov 2017, 5:28 PM
Saurabh Tiwari
Saurabh Tiwari - avatar
+ 2
thank you you are really helpful
13th Nov 2017, 5:29 PM
Chapay Gahramanov
Chapay Gahramanov - avatar
+ 2
netkos's method is much satisfactory than mine
13th Nov 2017, 5:31 PM
Saurabh Tiwari
Saurabh Tiwari - avatar
+ 2
anyway both are correct
13th Nov 2017, 5:32 PM
Chapay Gahramanov
Chapay Gahramanov - avatar
+ 2
Here you go, as promised. Hope that helps. It's rough idea of what you're looking for. https://code.sololearn.com/cxFMCyF5pI9j/#cpp #include <iostream> using namespace std; void getEachNum(int number) { if(number >= 10) getEachNum(number / 10); int num = number % 10; cout << num << ' '; } int main() { int userInput = 0; while(true){ cout<<"Please enter a number (10-99): "<<endl; cin>>userInput; if(userInput < 10 || userInput > 99) { cout<<"Number out of range! Try again."<<endl; continue; } else { getEachNum(userInput); break; } } return 0; }
13th Nov 2017, 5:36 PM
AgentSmith
+ 1
sorry i am really new here i started yesterday i really dont kjow what i am doing
13th Nov 2017, 5:20 PM
Chapay Gahramanov
Chapay Gahramanov - avatar
+ 1
following you :)
13th Nov 2017, 5:27 PM
Chapay Gahramanov
Chapay Gahramanov - avatar
0
I need it in c ++
13th Nov 2017, 5:09 PM
Chapay Gahramanov
Chapay Gahramanov - avatar
0
LOL, I wrote this on C++.
13th Nov 2017, 5:19 PM
Porf
Porf - avatar