### Array program

I have been working on this program as homework and cannot figure out why it will not execute. Any help would be much appreciated.

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980`` `````` #include #include using namespace std; int main() { //change the variable size to modify the amount of grades desired const int size = 5; int array[size]; int lowest = 101; int total = 0; double average; int i = 0; //loop through the array for (i = 0; i < size; i++) { //get inputs cout << "\nPlease enter grade " << i + 1 << ": "; cin >> array[i]; //check that value entered is between 0 and 100 while (array[i] < 0 || array[i] >100) { cout << "Wrong input. Please enter a value between 0 and 100 only." << endl; cout << "\nPlease Reenter grade " << i + 1 << " : "; cin >> array[i]; } } //pass the array to function getLowestGrade() instead, get the value as a return lowest = getLowestGrade(array); //loop through the array for (i = 0; i < size; i++) { //if the value of the array element isn't the lowest then we'll add it to the total(because you want to drop the lowest value) if (array[i] != lowest) { total = total + array[i]; } } //then take the total and divide it by the total sample (size minus one because we ditched the lowest grade) average = (total / (size - 1)); //print the average cout << average; //pause system("pause"); } int getLowestGrade(int array[]) { int lowest = 101; //loop through the array for (i = 0; i < size; i++) { while (array[i] < lowest) { lowest = array[i]; } } return lowest; }``````
No function prototype for `getLowestGrade`

Prototype:

`int getLowestGrade(int[], int);`

`getLowestGrade` has a variable `size` that doesn't exist for it and i isn't initialized either. Also while loop?

Corrected version:

 ``123456789101112131415`` ``````int getLowestGrade(int array[], int size) { int lowest = array[0]; //loop through the array for (int i = 1; i < size; i++) { if(array[i] < lowest) { lowest = array[i]; } } return lowest; }``````

main needs to `return 0;`

After that you will have to make some minor corrections in your `main()`
Last edited on
Topic archived. No new replies allowed.