#include <iostream>
using namespace std;
int main()
{
// Declare variable
ifstream inFile;
// Declare constant
const int MAX = 600;
// Declare an array of strings named name that holds up to MAX
string array [name] = MAX;
// Declare an array of whole numbers named grade that holds up to MAX
double array [grade] = MAX;
// Declare variables quantity, x, avg, and sum (initialized to zero) that hold whole numbers
int sum = 0, avg, x, quantity;
// Open input file
inFile.open("indata3.txt");
// Check if the file was opened
if (!inFile)
{
cout << "File was not found!" << endl;
return 1;
}
// Set x to 0
x = 0;
// Read name and grade from the file and assign them to name[x] and grade[x] respectively
cin >> name[x];
cin >> grade[x];
// While (not-end-of-file)
while(inFile)
{
//Increment x
x++;
// Read a name and a grade from the file and assign them to name[x] and grade[x] respectively
cin >> name[x];
cin >> grade[x];
}
// Print message
cout << "Enter quantity of grades to be processed (0-" << x << "): " << endl;
// Read a value from the keyboard and assign it to quantity
cin >> quantity;
// For (x = 0 to quantity-1)
for (x = 0; x <= quantity-1)
{
//16. Accumulate grade[x] in sum
}
// Assign to avg the value returned by average (sum, quantity)
avg = sum/quantity;
// Print "Average grade: ", avg
cout << "Average grade: " << avg << endl;
// Print "Name", "Grade", " Comment"
cout << "Name" << "," << "Grade" << "," << " Comment" << endl;
// For (x = 0 to quantity-1)
for (x = 0; x <= quantity-1)
{
// Print name[x], grade[x]
cout << name[x] << ", " << grade[x] << endl;
// If (grade[x] < avg)
if (grade[x] < avg)
{
// Print " below average"
cout << " below average" << endl;
}
// Else if (grade[x] > avg)
else if (grade[x] > avg)
{
// Print " above average"
cout << " above average" << endl;
}
// Else
else()
{
// Print " average"
cout << " average" << endl;
}
}
// Close the file.
inFile.close();
return 0;
}
Here are some of the errors our of the 20. Most repeat the undeclared identifier. Also not sure where I would need to add more curly brackets to make it syntactically correct. One more thing..how do I accumulate grade[x] into sum? Any help would greatly be appreciated thank you.
error C2065: 'name' : undeclared identifier
error C2075: 'array' : array initialization needs curly braces
error C2065: 'grade' : undeclared identifier
error C2371: 'array' : redefinition; different basic types
error C2440: 'initializing' : cannot convert from 'const int' to 'double [1]'
error C2228: left of '.open' must have class/struct/union1> type is 'int'
error C2143: syntax error : missing ';' before ')'
error C2059: syntax error : ')'
error C2143: syntax error : missing ';' before '{'
error C2228: left of '.close' must have class/struct/union1> type is 'int'