0

space between two inputs

Can you guys teach me how to make space between 2 inputs on the same line like this Cout<< “ enter 2 numbers: “;cin>>(part i ask you guys) And the output is: enter 2 number : I enter 1 and the output is: enter 2 number: 1 And the part i dont know how to do is when i enter another number the input must continute on the same line.exp i enter 3 : enter 2 number: 1 3

16th Oct 2017, 1:54 AM
Anh Lam
Anh Lam - avatar
2 RĂ©ponses
+ 14
other nice approaches for inputting several numbers might be the followings: /////// method #1 ////////// #include <iostream> using namespace std; int main() { int n, m; cout << "Enter 2 numbers\n"; cout << "num 1: "; cin >> n; cout << "num 2: "; cin >> m; } Output: Enter 2 numbers num 1: 25 num 2: 41 /////// method #2 ////////// #include <iostream> using namespace std; int main() { int n[2]; cout << "enter 2 numbers\n"; for (int i = 0; i < 2; ++i) { cout << "num " << i + 1 << ": "; cin >> n[i]; } } Output: Enter 2 numbers num 1: 25 num 2: 41
16th Oct 2017, 7:18 AM
Babak
Babak - avatar
+ 4
cin>>a>>b; will read 2 inputs and u can make use of it
16th Oct 2017, 2:13 AM
Nanda Balakrishnan