For this i have to first specify how many numbers i am going to enter. Then i have to enter how many numbers i said.
For ex: i say i will enter 4 numbers then i enter 4 numbers. Now i know how to do what i mentioned. The only problem i have is making this code work with random numbers. Say next time i want to enter 10 numbers. I am confused on how i would write this code to work for every number i want to use. Or if i wanted to enter 3 numbers or 7 numbers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
usingnamespace std;
int main()
{
int counter = 0,
num;
cout << "Please enter how many numbers you are going to use." << endl;
cin >> num;
cout << "Please enter " << num << " integer(s) seperated" << endl;
cin.get();
cin.get();
return 0;
}
I'm not exactly sure what your asking, but I believe the answer to your question is that you will need to use a loop to allow the user enter a number as many times as they specified. For example, you could do something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
int num, temp;
vector<int> nums;
cout << "Please enter how many numbers you are going to use." << endl;
cin >> num;
for (int count = 0; count < num; count++)
{
cout << "Please input a number for position " << count << endl;
cin >> temp;
nums.push_back(temp);
}
cout << "Nums: ";
for (int count = 0; count < num; count++)
{
cout << nums.at(count);
}
cout << '\n';