array range specified by user?

So this code is supposed to take a range from the user and process an array in that range. Then it is supposed to output it backwards and only the positive numbers. I got it to generate an array and process it backwards and print both out. My problem is I can't figure out how to connect the range the user enters with the array. Also it only prints out negative numbers for some reason and that is the opposite of what I'm trying to do. I hope that makes sense. I've been stuck for a while. Any helpful hints you can give me are appreciated!

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
31
32
33
34
35
36
37
38
39
40

int main() {
	const int SIZE = 10;
	int highest, lowest;
	int test[SIZE];

	cout << "please enter highest value: ";
	cin >> highest;

	cout << "Please enter lowest value: ";
	cin >> lowest;

	 for (int i = 0; i < SIZE; i++) {
			 test[i] = 7 * i;
	}

	
	
	//for (int i = 0; i < SIZE; i++) {
	//if (test[i] > 0 && test[i] >= lowest && test[i] <= highest) {
	//	}
	//}

	int newtest[SIZE];
	rev(test, newtest, SIZE);
	cout << "original array: ";
	printArray(test, SIZE);
	cout << endl;

	cout << "reversed array: ";
	printArray(newtest, SIZE);
	cout << endl;


	system("pause");
	return 0;
	

}
Last edited on
Also it only prints out negative numbers for some reason

I'm not sure what you're talking about. You fill it with 7 * i, that's what it prints out for me.

As for the range thing -


1
2
3
4
5
6
7
8
9
10
11
int range(int lowest, int highest)
{
	static bool first = true;
	if (first)
	{
		srand(time(NULL));
		first = false;
	}

	return rand() % highest + lowest; // return number between highest and lowest
}

1
2
3
for (int i = 0; i < SIZE; i++) {
		test[i] = range(lowest,highest); // fills it with numbers between highest and lowest
	}
thanks for your help!! works perfect now :)
Topic archived. No new replies allowed.