sentinel loop problems.

Im having an issue with this loop.

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
41
42
#include <iostream>
#include <string>

using namespace std;

void inputArray(double*);
//void calculate();
//void display();

int main() {
	double inputGrades[30];
	double *grades;

	grades = inputGrades;
	
	inputArray(grades);

	system ("pasue");
	return 0;
}

void inputArray(double *grades) {

	int index = 0;
	
	cout << "Enter a Grade (or -1 to quit): ";
	cin >> grades[index];

	while (grades[index] != -1); {
		index++;
		cout << "Enter a Grade (or -1 to quit): " << endl;
		cin >> grades[index];
	}
}

void calculate() {

}

void display() {

}


For the assignment, all parameters have to be pointers, and I have to use a sentinel loop to read in 30 values into an array. However, when I enter a normal integer into the cin portion, it doesnt loop. It doesnt do anything.
You shouldn't have a semicolon after your while loop on line 29. With the semicolon, your code is equivalent to:
1
2
3
4
5
6
while (grades[index] != -1) {
    // do nothing
}; // <-- the semicolon you have on line 29
index++;
cout << "Enter a Grade (or -1 to quit): " << endl;
cin >> grades[index];

Remove it and it ought to work.
Oh, silly me.
Now I am having an issue with the program closing after the -1. I dont want it to terminate. I was going to add the other functions to create a histogram and display all the grades.
Nevermind. Type in ("pause"). I should not be coding with no sleep...
Topic archived. No new replies allowed.