### Arrays and Averaging

I know what I need to do in this program, I just don't know how to do it.

This program needs to show the the average of grades after the user decides what quiz to drop. Except I don't know how to do that. I tried sum_points_possible += points_possible_array[i - quiz_to_drop] and it came out with infinity. I would love any help. Thanks:)

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283`` ``````#include #include #include using namespace std; int main() { const int MAX_QUIZ = 15; double points_possible, points_earned, points_possible_array[MAX_QUIZ], points_earned_array[MAX_QUIZ], sum_points_possible = 0, sum_points_earned = 0, dropped_quiz_avg; int quiz_to_drop, highest_quiz_num = 0, quiz_number; ifstream in_file; in_file.open("quizinfo.txt"); if (!in_file) { cout << "Input failed to open." << endl; return 1; } cout << "Please enter the data asked below in the input file." << endl << endl; cout << "The end of the data is indicated by a negative quiz" " number and 0s for the other" " two data values on the line." << endl << endl; cout << "Quiz number " << setw(10) << " Maximum points on the quiz " << setw(10) << " Points earned" << endl << endl; in_file >> quiz_number >> points_possible >> points_earned; cout << "Please enter the quiz number you want to drop."; cin >> quiz_to_drop; while (quiz_number >= 0 && points_possible != 0 && points_earned!=0) { points_possible_array[quiz_number] = points_possible; points_earned_array[quiz_number] = points_earned; highest_quiz_num = quiz_number; in_file >> quiz_number >> points_possible >> points_earned; } for (int i = 0; i <= highest_quiz_num; i++) { sum_points_earned += points_earned_array[i] ; cout << points_earned_array; } for (int i; i <= highest_quiz_num; i++) { sum_points_possible += points_possible_array[i]; } cout << "Quiz number " << setw(5) << " Maximum points on the quiz " << setw(5) << " Points earned" << endl << endl; for(int i = 0; i <= highest_quiz_num; i++) { cout << i <<" " << points_possible_array[i] << " "<< points_earned_array[i] << endl << endl; } dropped_quiz_avg = (( sum_points_earned)/(sum_points_possible) * 100); cout << "The average grade is " << setprecision(0) << fixed << dropped_quiz_avg; in_file.close(); return 0; }``````
Please post a sample of your input file. And also provide a sample of what you input into the program and what output you expect the program to produce.

Input is:

0 20 20
1 20 20
2 20 20
3 20 20
4 20 20
-1 0 0

 ```Please enter the data asked below in the input file. The end of the data is indicated by a negative quiz number and 0s for the other two data values on the line. Quiz number Maximum points on the quiz Points earned Please enter the quiz number you want to drop. 4 0x28aae00x28aae00x28aae00x28aae00x28aae0Quiz number Maximum points on the quiz Points earned 0 20 20 1 20 20 2 20 20 3 20 20 4 20 20 The average grade is inf```
First you should be using a counter that counts the number of tests for your index values. Don't rely on the file being correct.

Next this line:
` cout << points_earned_array;`
Is printing the address of your array. Is that really what you want?

Next this line looks really wrong.
` dropped_quiz_avg = (( sum_points_earned)/(sum_points_possible) * 100);`

Is that how you compute an average? I always thought an average is computed by something like sum of items / number of items.

cout << points_earned_array; Was used to see if what was going wrong with the program. I was going to delete it after I fixed the program.

dropped_quiz_avg = (( sum_points_earned)/(sum_points_possible) * 100);
this is the confusing part because the quizzes can be vary in max points possible. That's why I added all of the points earned and divided it by points possible. I don't understand how I can subtract the quiz the user wants to drop from the over all total.
That is not how you compute an average! You compute an average by adding all the points earned and then dividing that sum by the number of quizzes . The number of possible points is not relevant to the average of quizzes. If you are going to throw out a score you either don't add that score to your total scores or you subtract that score from the total. Then you divide by the number of quizzes - 1 to get your average.

Jim
I changed everything like you said and the new output is:

 ```Please enter the data asked below in the input file. The end of the data is indicated by a negative quiz number and 0s for the other two data values on the line. Quiz number Maximum points on the quiz Points earned Please enter the quiz number you want to drop.4 Quiz number Maximum points on the quiz Points earned 0 20 20 1 20 20 2 20 20 3 20 20 4 20 20 The average grade is -5000```
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283`` ``````#include #include #include using namespace std; int main() { const int MAX_QUIZ = 15; double points_possible, points_earned, points_possible_array[MAX_QUIZ], points_earned_array[MAX_QUIZ], sum_points_possible = 0, sum_points_earned = 0, dropped_quiz_avg; int quiz_to_drop, highest_quiz_num = 0, quiz_number; ifstream in_file; in_file.open("quizinfo.txt"); if (!in_file) { cout << "Input failed to open." << endl; return 1; } cout << "Please enter the data asked below in the input file." << endl << endl; cout << "The end of the data is indicated by a negative quiz" " number and 0s for the other" " two data values on the line." << endl << endl; cout << "Quiz number " << setw(10) << " Maximum points on the quiz " << setw(10) << " Points earned" << endl << endl; in_file >> quiz_number >> points_possible >> points_earned; cout << "Please enter the quiz number you want to drop."; cin >> quiz_to_drop; while (quiz_number >= 0 && points_possible != 0 && points_earned!=0) { points_possible_array[quiz_number] = points_possible; points_earned_array[quiz_number] = points_earned; highest_quiz_num = quiz_number; in_file >> quiz_number >> points_possible >> points_earned; } for (int i = 0; i <= highest_quiz_num; i++) { sum_points_earned += points_earned_array[i] ; } for (int i; i <= highest_quiz_num; i++) { sum_points_possible += points_possible_array[i]; } cout << "Quiz number " << setw(5) << " Maximum points on the quiz " << setw(5) << " Points earned" << endl << endl; for(int i = 0; i <= highest_quiz_num; i++) { cout << i <<" " << points_possible_array[i] << " "<< points_earned_array[i] << endl << endl; } dropped_quiz_avg = (( sum_points_earned)/(quiz_number - 1) * 100); cout << "The average grade is " << setprecision(0) << fixed << dropped_quiz_avg; in_file.close(); return 0; }``````
` dropped_quiz_avg = (( sum_points_earned)/(quiz_number - 1) * 100);`

First are you trying to compute the average of the dropped score?

Or the average of the scores?

Where have you assigned any value to quiz_number?

Where have you subtracted the quiz you want to drop from the total?

Why are you dividing by 100?

You may want to turn off your computer, take pencil and paper and compute the average by hand. If you don't know how to do the math you will probably never be able to finish this program.

Thank you Jilb for all of the encouraging words. you helped me a lot...
Topic archived. No new replies allowed.