Join 137,261 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,515 people online right now. Registration is fast and FREE... Join Now!
Hey guys I need help. In my project, I have to use void calculateaverage and void calculategrade with &'s in the parameters..
basically the code has to read a students name with his/her 5 test scores then it has to compute the average test score for each student and assign an appropriate grade letter A B C D E where A is 90 - 100, B is 80-89, C is 70-79.. D is 60-69.. and D is 0-59..
the function void calculateaverage has to determine the average of the five test scores using a loop and sum the five scores.. this function cant output the average because the average has to be computer in the main function..
the calculategrade function has to determine and return each students grade and again it has to be outputted in the main function..
the people in the class are in a seperate file .txt listed like this Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 .. etc.. there are 10 students with random grades..
Every function body should be starting with { after the heading (which they do in your code) and end with a } That last } is where some functions are failing.
WoW...That's a lot of mistakes. I'm glad I had the patience to fix the code. Here goes. Get yourself a cola and read on.
CODE
if (!inFile) { cout << "File cannot be opened" << endl; return 1; }
inFile.open("C:\\Documents and Settings\\kfg5\\Desktop\\gpadata.txt");
This makes no sense. You should check if the file can be opened or not after an attempt has been made to open it. Interchange the positions of the two statements.
Firstly, for passing arguments, you don't have to mention the datatypes of the passed variables. Second, since the calculateAverage() function returns void (ie. doesnt return anything) remove the avg= portion. avg is passed by reference and will contain the average after the function call. The corrected line of the code shown above will look like this:
CODE
calculateAverage(inFile,avg);
CODE
letterg = calculateGrade(avg);
letterg is not defined. Add the char letterg; declaration in the beginning of main().
Firstly, avg does not exist. Replace the argument variable name 'score' with avg. Secondly, after an else keyword, if you choose to give another condition, you have to add the keyword if.
P.S : You have mentioned the function prototype of only one of the overloaded functions. While this compiles with VC++, you should still write it's function prototype like this:
CODE
double calculateAverage(int s1, int s2, int s3, int s4, int s5);
The calculate average has to be a void function and both functions calcaverage and calcgrade can only output the grade and average in the main function..