piped input to fill array of unknown size

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
int tempSize;

	//bool file = false;
	std::string fileName;
	// diddnt know how else to make a variable limit for the amount of numbers input without a vector.
		cout << "how many numbers will be in your array? ";
		cin >> tempSize;
		if (cin.fail()) {
			cin.clear();
			cin.ignore();
			cout << "There was an error with the number you put in, try again: ";
			cin >> tempSize;
		}
		//	array1(tempSize);
		//cout << "Enter your entire first array: ";
		
		cout << "fill your array by entering a row of numbers: ";//seperated by white space
		int n;
			for (int i = 0; i < tempSize; i++) {
				
					cin>>n;
					if (cin.fail()) {
						cin.clear();
						cin.ignore();
						
					}
					else {
						array1[i] = array1[n];
					}
				}


This is what im using. The input will be an array of ints from 10 to 100 ints long. is there a way to allocate the array without asking the user for the # of #s? and is there a better way to fill them? Not allowed to use vector library or math library
Last edited on
http://www.cplusplus.com/reference/vector/vector/push_back/

> array1[i] = array1[n];
¿what do you think you are doing there?

> from 10 to 100 ints long.
int array[100];
but keep track of the size
Last edited on
Topic archived. No new replies allowed.