Please help!

I am admittedly very new to c++ and am working on a project, with which I am very stuck.
((I articulate that I am very new as I know this is a forum where most assume the posters know the basics. Please forgive me if I am missing something incredibly obvious.))

Program will read data from a file which includes student names and grades, and will prompt user to enter a student's name for grade information. Then the program will calculate said grades with respective scores and assignment percentages. Then this data will be used to calculate a final numerical grade. The program will then assign a letter grade based on the final numerical grade. Descriptive information will output regarding the student's grades.

I am running into issue with the grade values computing incorrectly (though we are given a specific formula to use verbatim), and gaining general understanding of what is wanted overall.

The instruction is to abide by these stipulations:

• Create an array of the structure in main to hold 10 components, i.e., an array of size 10.
• Using a function, open the input file, the output file for report and an error file to log errors. If any file fails to open, display a proper message to the customer and exit the program. Request the input and report file names from the user. The error file name may be a literal. Call the function from main.
• Using a function, close all files prior to program end. Call this function from main.
• Read the file and process the data via a function. This function will call the remaining functions EXCEPT the output/display function. Read until end of file. Do not “hard-code” the number of rows to read. Read the first name and last name into the student array data members. Since the array may hold more components than there is data, use and increment a counter to count how many rows “actually” read. Pass that counter into the output function.
• The other data for the student should be read into non-structure variables.
• There will be errors in the file, i.e., divide by zero. If a divide by zero error is encountered, do not calculate the numerical grade, lookup the final letter grade, lookup the comment or output the student grade information. Write an error to the error file indicating that the grade cannot be calculated for the student. Include the student name. If there is an error, set the student’s numerical grade to 0, letter grade to space (‘ ‘) and comment to “Error in Data”.
• Calculate numerical grade. Store the numerical grade in the student array data member. You may call this function from the read and process function.
• Look up the final letter grade using a function. Store the letter grade in the student array data member. You may call this function from the read and process function.
• Retrieve the comment via a function. Store the comment in the student array data member. You may call this function from the read and process function.
• Using a function, for each student, output the following to the console (screen) and the output file in a neat, readable format. Output each input line on one output line. Use manipulators to output values in readable columns, set any floating-point numbers to 2 decimal places. Call this function from main.


This is what I have so far:




#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

int main()

{
int totalGrades; // This is the total number of test grades

int grade; // This is the student's test grade

ifstream inFile; // This is a declaration of the inFile that holds all the grades

string fileName; // This is the filename that the user will enter

string name; // This is the name of the student

string surname;

int gradeCount; // This is to keep count of the number of grades entered

int hwGradesN; // Number of homework grades

int hwGradesV; // Homework grade values

float hwGradesP; // Homework grade percentage

int progGradesN; // Number of program grades

int progGradesV; // Program grade values

float progGradesP; // Program grade percentage

int examGradesN; // Number of exam grades

int examGradesV; // Exam grade values

float examGradesP; // Exam grade percentage

int totalHWpoints; // Total homework points earned

int totalProgpoints; // Total program points earned

int totalExampoints; // Total exam points earned

int maxHWpoints; // The maximum points available for homework grades

int maxProgpoints; // The maximum points available for program grades

int maxExampoints; // The maximum points available for exam grades

int maxCoursepoints; // The maximum points available for the course

float finalGrade; // Final grade

float finalGradeLetter; // Letter grade assigned from numerical grade

float average; // The average of all the grades

cout << "Enter the input file name to read student grades: ";

cin >> fileName;

// Open the file with the grades

inFile.open(fileName.c_str ());

// Check to make sure the file opened correctly

if (!inFile)

{
cout << "File did not open correctly." << endl;
return 1;
}

// Reads scores from file


while(!inFile.eof()){

totalHWpoints=0;

totalProgpoints=0;

totalExampoints=0;

inFile>>name;

inFile>>surname;

inFile>>hwGradesN;

maxHWpoints = hwGradesN*100;

while(hwGradesN--){

inFile>>hwGradesV;

totalHWpoints+=hwGradesV;

}

inFile>>hwGradesP;

maxProgpoints = hwGradesP*100;

inFile>>progGradesN;

while(progGradesN--){

inFile>>progGradesV;

totalProgpoints+=progGradesV;

}

inFile>>progGradesP;

inFile>>examGradesN;

maxExampoints = examGradesN*100;

while(examGradesN--){

inFile>>examGradesV;

totalExampoints+=examGradesV;

}

inFile>>examGradesP;

maxCoursepoints = (maxExampoints + maxHWpoints + maxProgpoints);

finalGrade= (((totalHWpoints/maxHWpoints) * hwGradesP) + ((totalProgpoints/maxProgpoints) * progGradesP) + ((totalExampoints/maxExampoints) * examGradesP)) * 100;

// Calculate the average.

average = (finalGrade) / (maxCoursepoints);

cout << average << endl; // Display the average.

if (average>=90) finalGradeLetter = 'A';

if (average<90 && average >=80 ) finalGradeLetter = 'B';

if (average<80 && average >=70) finalGradeLetter = 'C';

if (average<70 && average >=60) finalGradeLetter = 'D';

if (average<=60) grade = 'F'; finalGradeLetter = 'F';

cout << "Final Grade of "<<name<<" "<<surname<<": " << finalGradeLetter << endl;

}

return 0;
}
http://www.cplusplus.com/articles/jEywvCM9/
Please edit your post to include code tags.
after you tag it up, can you also explain what the input is, what the expected output is, what the actual output is, and if you know, where the incorrect output was produced (line #).

Take the bullet list from the instructions and paste it into your code as a comment. As you write your code, move the sentences/phrases from the instructions to the code that implements that part. Here are the instructions with some important pieces that you're missing underlined:
Create an array of the structure in main to hold 10 components, i.e., an array of size 10.
Using a function, open the input file, the output file for report and an error file to log errors. If any file fails to open, display a proper message to the customer and exit the program. Request the input and report file names from the user. The error file name may be a literal. Call the function from main.
Using a function, close all files prior to program end. Call this function from main.
Read the file and process the data via a function. This function will call the remaining functions EXCEPT the output/display function. Read until end of file. Do not “hard-code” the number of rows to read. Read the first name and last name into the student array data members. Since the array may hold more components than there is data, use and increment a counter to count how many rows “actually” read. Pass that counter into the output function.
• The other data for the student should be read into non-structure variables.
• There will be errors in the file, i.e., divide by zero. If a divide by zero error is encountered, do not calculate the numerical grade, lookup the final letter grade, lookup the comment or output the student grade information. Write an error to the error file indicating that the grade cannot be calculated for the student. Include the student name. If there is an error, set the student’s numerical grade to 0, letter grade to space (‘ ‘) and comment to “Error in Data”.
• Calculate numerical grade. Store the numerical grade in the student array data member. You may call this function from the read and process function.
• Look up the final letter grade using a function. Store the letter grade in the student array data member. You may call this function from the read and process function.
• Retrieve the comment via a function. Store the comment in the student array data member. You may call this function from the read and process function.
• Using a function, for each student, output the following to the console (screen) and the output file in a neat, readable format. Output each input line on one output line. Use manipulators to output values in readable columns, set any floating-point numbers to 2 decimal places. Call this function from main.
Topic archived. No new replies allowed.