0

How can i repeat input (cin) in my program

Input Repetition

24th Jul 2020, 2:15 AM
Faruq
Faruq - avatar
7 Answers
+ 2
By doing writing them multiple times?? cin >> a; cin >> b; cin >> c;
24th Jul 2020, 2:17 AM
Saphal Poudyal
Saphal Poudyal - avatar
+ 2
Faruq You do it normally. int a; cin >> a; cout << a << endl; cin >> a; cout << a << endl;
24th Jul 2020, 2:25 AM
Saphal Poudyal
Saphal Poudyal - avatar
+ 1
You can use loops such as for loop, do-while and while loop
24th Jul 2020, 2:25 AM
Jay Gilbert Garzon
Jay Gilbert Garzon - avatar
+ 1
It is more efficient if u use looping instead of manually using cin Lets say u want to get user input 5 times 1. via For loop for(int i = 0; i <= 5; i++){ cin >> a; } 2. via while loop int i = 0; int noOfInput = 5; while( i <= noOfInput){ cin >> a; i++; } 3. Using do-while loop int i = 0; int noOfInput = 5; do{ cin >> a; i++; }while(i<=noOfInput);
24th Jul 2020, 2:42 AM
Jay Gilbert Garzon
Jay Gilbert Garzon - avatar
+ 1
Thanks Jay Gilbert Garzon
24th Jul 2020, 2:45 AM
Faruq
Faruq - avatar
0
What about for a single variable??
24th Jul 2020, 2:20 AM
Faruq
Faruq - avatar
0
Thanks çheyat
24th Jul 2020, 2:27 AM
Faruq
Faruq - avatar