this is the code i have:
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
ifstream infile("grade_data.txt");
string answers, key;
int num_grades;
void highest(double [], int);
void lowest(double [], int);
const int NUM_QUESTIONS = 10;
double scores[NUM_QUESTIONS + 1];
int results; //how many right answers
int wrong=0; //how many wrong answers
double total=0.00; //total of all answers, used for average.
double average=0.00;
double percent[50]; //% right of answers
const int x=10;
int t1[x+1];
int main()
{
int b;
if (!infile)
{
cout << "Error opening file\n\n";
system("pause");
}
else
cout << "File Successfully Opened\n\n";
infile >> key;
cout<<" KEY\n";
for (int i=0; i < key.length(); i++)
cout<<" | "<<key[i]<<" | \n";
cout<<endl;
infile >> answers;
while (!infile.eof() && answers != " ")
{
num_grades++;
for (int a=0; a < answers.length(); a++)
cout<<" | "<<answers[a]<<" | \n";
for(b = 0; b < NUM_QUESTIONS; b++)
{
if(key[b] == answers[b])
{
results++;
cout<<"CORRECT ANSWERS: "<<b+1<<"\n"; //which questions they are getting right.
t1[b]++;
}
else
wrong++;
}
percent[num_grades]=results*10;
cout<<"Student "<<num_grades<<": Made: "<<fixed<<setprecision(0)<<results<<
" Missed: "<<wrong<<" Grade: "<<percent[num_grades]<<"%\n";
for (int c=0; c<1;c++)
total+=results;
average=(total/num_grades);
infile >> answers;
results=0;
wrong=0;
}
for (int i=0;i<9;i++)
cout<<"\nQuestion "<<i+1<<" - "<<t1[i];
cout<<"\nQuestion 10 - "<<t1[9];
cout<<"\n\nThe average of "<<num_grades<<" tests is: "<<fixed<<setprecision(2)<<average<<endl;
highest(percent, 10);
lowest(percent, 10);
cout<<"\n\n";
system("pause");
}
void highest(double amt[], int length) //function to find the highest value in array
{
double highest;
highest = amt[0]; // sets the first value in array to variable 'highest'
for (int i=1; i < length; i++) // counts i amount of times
{
if (amt[i] > highest) // as the counter goes from 1 to the value of a, each number in the array will
highest=amt[i]; // be checked for the highest value. highest will be stored in variable 'highest'
}
cout<<"\nHighest : "<<highest;
}
void lowest(double amt[], int length) // function to find the lowest value in array 'ptr'
{
// the lowest function below is the exact same as the 'highest' function,
double lowest;
lowest= amt[length-1];
for (int i=0; i< length; i++)
{
if(amt[i] < lowest)
lowest=amt[i];
}
cout<<"\nLowest : "<<lowest;
cout<<"\n\n\n";
}
it compiles but it always returns 0 for the lowest score. it should be higher than that.
heres the grade_data.txt info
bccbbadbca
cbabddcbaa
accabcbbac
babccabadd
any help is appreciated