help with while and for

Create a program that will accept 10 numbers between 1 and 20 as input. If the user enters an invalid number re-prompt with an error message for the number. Output the list of numbers in numerical order.





#include <iostream>
#include <vector>
#include <algorithm>


using namespace std;

int main()

{

vector <int> number;
int x;

while(vec.size() < 10)
{

//output: "Enter a number between 1-20: "
cout << "Enter a number between 1-20: ";

//read an input into x
cin >> x;

//if ( x >= 1 AND x <= 20 )
if( x >= 1 && x <= 20)
{
//add x to the number vector
vec.push_back(x);
}
//else
else
{
//output: "Bad input: Try again."
cout << "Bad input: Try again." << endl;
}

sort (number.begin(),number.end()); // sorting

cout <<"\n Print integers in ascending order :"<< endl;

for ( int i=0; i<number.size(); i++)
{
cout <<"\n"<<number.at(i) << endl;

}
system("PAUSE");
return 0;

}
This is the code i have assembled and it gives me the errors:

in function int main()
Vec undeclared
Don't post multiple threads on the same thing. http://www.cplusplus.com/forum/beginner/128864/
Last edited on
Topic archived. No new replies allowed.