0
How can i repeat input (cin) in my program
Input Repetition
7 Answers
+ 2
By doing writing them multiple times??
cin >> a;
cin >> b;
cin >> c;
+ 2
Faruq
You do it normally.
int a;
cin >> a;
cout << a << endl;
cin >> a;
cout << a << endl;
+ 1
You can use loops such as for loop, do-while and while loop
+ 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);
+ 1
Thanks Jay Gilbert Garzon
0
What about for a single variable??
0
Thanks çheyat