Hello, I am trying to read the following from an input file into the console using a do while loop. The first column is the quiz number, second is earned points and the third is the max points earned. The 1000 is a Sentinel value.
So, I set i equal to zero and ran the following. I got this in the build message part
error: invalid types 'int[int] ' for array subscript
error: invalid types 'double[int] ' for array subscript
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
const int MAX = 20;
const double SENTINEL = 1000;
int quiz_no[MAX + 1];
int quiz;
double earned,
max_earned;
int i = 0;
double pts_earned[MAX],
pts_max[MAX];
ifstream fin;
fin.open("quizinfo.txt");
if (!fin)
{
cout << "Input file open failure\n";
return 1;
}
do
{
cout << "NO.\tEarned\tMax"
<< setprecision(2) << fixed;
fin >> quiz[i] >> earned[i] >> max_earned[i];
quiz_no[i]= quiz;
pts_earned[i] = earned;
pts_max[i] = max_earned;
cout << endl
<< quiz << "\t" << earned << "\t" << max_earned;
}while (quiz != SENTINEL);
I want to drop a certain quiz grade but the average isn't working out. Also, I want the stuff in the input file to keep repeating every time I choose to drop a different quiz grade. Do I include the following in the do while loop as well?
while (count <= MAX && pts_earned >= 0)
{
total_earned += pts_earned[count];
count = count + 1;
fin >> pts_earned[count]; //Get the next grade
}
while (count < MAX && pts_max >= 0)
{
total_earned += pts_max[count];
count = count + 1;
fin >> pts_max[count]; //Get the next grade
}
average = (total_earned-pts_earned[count])/(total_max-pts_max[count])*100;
if (drop > 0)
{
cout << endl << endl;
cout << "Please select the quiz number you want to drop or any negative"
<< " number to exit the program: ";
cin >> drop;
cout << setprecision(2) << fixed
<< "If you drop quiz #" << drop << " your average will be " << average;
}
else
{
cout << "You have chose to exit the program.";
}