Limited number of input.
Guys, I need your help. How can i make an input on a limited loop only? Like i want to ask the user to input only 6 numbers. Thnx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#include <iostream>
#include <vector>
int main()
{
const std::size_t MAX_NUMBERS_ALLOWED = 6 ;
std::vector<int> list_of_numbers ;
std::cout << "enter up to " << MAX_NUMBERS_ALLOWED << " numbers\n" ;
int number ;
while( list_of_numbers.size() < MAX_NUMBERS_ALLOWED &&
std::cout << "? " &&
std::cin >> number )
{
list_of_numbers.push_back(number) ;
}
std::cout << "\nyou entered " << list_of_numbers.size() << " numbers: [ " ;
for( int n : list_of_numbers ) std::cout << n << ' ' ;
std::cout << "]\n" ;
}
|
Topic archived. No new replies allowed.