I am trying to come up with a solution for finding the number of integers that i can input into an array. What i mean is i have an array with a set size, but i want to be able to enter as little or as many numbers without there being a set number to enter. Then im trying to figure out how to get that number of integers i put in and have it printed out. I'm pretty sure i have to use counters as for what im told, but how do i go about using them in this situation? The code i have so far is here. if anyone could help that would be great! Thanks.
#include <iostream>
#include <vector>
int main()
{
std::vector<int> array(1);
int i = 0;
unsignedint num = 0;
std::cout << "Enter an integer: ";
std::cin >> num;
std::cin.ignore();
// do error checking
array[i] = num;
// ask if user wants to enter another digit, if yes:
array.reszie(array.size()+1);
// get more imputs, incrememnt i and assign num to the vector...
// if no, output vector content and quit
std::cin.get();
return 0;
}
ok i see. Now would this still operate if i were to try and find the mode by using my array this way with vectors? I know i would have to switch things around a bit, but i was curious before i run into a headache trying to do something that might not be possible.