How do I accept multiple numbers
Sep 22, 2018 at 5:04am UTC
Write a program that will accept a short value from 10 to 99 and display them per digit (separated by a space).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#include <iostream>
#include "_pause.h"
using namespace std;
int main(){
int num;
cout << "Enter a number from 10 to 99: " ;
cin >> num;
if (num > 9 && num < 100){
cout << num;
}
cout << endl;
std::cin.get();
_pause();
return EXIT_SUCCESS;
}
How do I accept multiple numbers?
Sep 22, 2018 at 5:26am UTC
1 2 3 4 5
if ( num > 9 && num < 100 ) { // if it is a positive two digit number
std::cout << num/10 /* first digit eg. 78/10 == 7 */ << ' ' /* space */
<< num%10 /* second digit eg. 78%10 == 8 */ << '\n' /* new line */ ;
}
Sep 22, 2018 at 5:44am UTC
wow thank you
Sep 22, 2018 at 5:47am UTC
what if I use two functions to do this.. is it possible? Because the problem came from the topic of 'Functions Procedures'
Sep 22, 2018 at 6:12am UTC
It is possible. Try to do it.
Sep 22, 2018 at 6:42am UTC
I've done it. Thank you!
Topic archived. No new replies allowed.