can someone explain the vector to me.
I am writing a project where you input a number and if the random number guess the number you put in you win. I have to use vectors but I don't understand where and how to use them my book is no help as well.
here is my program
# include <iostream>
#include <iomanip>
# include <string>
#include <vector>
using namespace std;
int main ()
{
int num1, n;
string answer;
vector<int> vNums;
vNums.push_back(n);
vNums.push_back(n);
vNums.push_back(n);
do
{
cout << "enter a number";
cin >> n;
cin.ignore();
if (num1 > 1 && num1 < 9) //== means equal to.
{
int num1= rand();
cout << "your random number is: ";
cout << num1 << vNums.size() << endl;
cout << "\n one digit big";
}
else if (num1 > 10 && num1 < 99)
{
cout << "\n two digits big";
}
else
{
cout << "out of range";
}
cout << "\n would you like to try again? yes/no "<<'\n';
getline(cin,answer);
}
while (answer == "yes");
system ("pause");
return 0;
}
Vectors are similar to arrays except their size does not have to be declared (or initialised) at compile time. Their at() function keeps track of their size.
Firstly read the article suggested by helios then ask your questions.
Do you have a specific problem with your program? What errors are you getting?
rgds.
p.s. It would help others if you wrapped your code with code tags,click#.