### Confused about test score curve

closed account (Ebf21hU5)
I have been able to execute each part of this assignment except for the grading curve. We have to get 5 test scores from user input, configure the highest score under a function called findHighest, and then have the program execute the grade curve for each test score. Here are the instructions:

b) void Curve() is passed the 5 test scores, as 5 reference parameters. The function first calls the function findHighest to get the largest value.
It then curves each test score, by dividing it by the largest value.

Here's what I have. Any suggestions are greatly appreciated.

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768`` ``````#include #include using namespace std; int main() { return 0; } float getScore() { float testScores, sum; for (int n=1; n<6; n++) { cout << "Please enter your test score " << n << endl; cin >> testScores; if (testScores<0 || testScores>100) { cout << "That input is invalid. Score must be between 0 and 100." << endl; break; sum += testScores; } } system("PAUSE"); return testScores; } float findHighest() { float Score1, Score2, Score3, Score4, Score5; cout << "Enter test score 1 " << endl; cin >> Score1; cout << "Enter test score 2 " << endl; cin >> Score2; cout << "Enter test score 3 " << endl; cin >> Score3; cout << "Enter test score 4 " << endl; cin >> Score4; cout << "Enter test score 5 " << endl; cin >> Score5; float highestScore = Score1; if (Score2>highestScore) highestScore = Score2; if (Score3>highestScore) highestScore = Score3; if (Score4>highestScore) highestScore = Score4; if (Score5>highestScore) highestScore = Score5; return highestScore; } void Curve(float Score1,float Score2,float Score3,float Score4,float Score5) { findHighest(); float Curve1 = Score1/highestScore; float Curve2 = Score2/highestScore; float Curve3 = Score3/highestScore; float Curve4 = Score4/highestScore; float Curve5 = Score5/highestScore; cout << "The curves for each test score are : " << endl; cout << " " << Curve1 << Curve2 << Curve3 << Curve4 << Curve5 << endl; return 0; }``````
Last edited on
Suggestions for what? Is the program working? If not, what are the indications and/or error messages that it isn't?

Only thing I can see is that the statement where you sum the test scores is inside the if loop testing to see if the inputted score is outside the 0-100 range. I'm assuming you want it to only sum the good scores, so that should prolly be after the close brace of that loop. Also, you have NOTHING in your main(). Well, except return 0;, so that's the ONLY thing this program will do. You have to call any functions from within main. The declarations and such can be outside, but at least the function calls must be within main, unless your calling a functions from within a function.

Oh, and you are entering the scores in both the getScore() and findHighest() functions. Seems odd to be doing it in both, or rather not odd but inefficient.

What you could just do is use an int array (if you've covered them that is) or declare the 5 test score variables inside main so they have scope over all the functions. This way you'd only have to enter them once. And an array would be pretty easy to sum over, and also to compare scores to find the highest.

I honestly don't see how this executed at all though tbh without any calls in main. :)
Last edited on
closed account (Ebf21hU5)
It didn't execute. I had 6 errors but all 6 of them were referring to "highestScore" in the void Curve() function not being declared, nothing serious. I have a hard time grasping the concepts of c++ so that's why some of the concepts I use in my coding are strange. Thank you. I will take what you said, apply it to my code and repost it.
Last edited on
closed account (Ebf21hU5)
I included main just because you kinda have to but my functions are not included in main because they have their own local definitions. I'm not really sure I need main to do anything. I am only getting one error now which is C2448: 'Curve' : function-style initializer appears to be a function definition. How should I go about fixing this.

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768`` ``````#include #include using namespace std; float Score1, Score2, Score3, Score4, Score5; float highestScore = Score1; int main() { return 0; } float getScore() { float testScores; for (int n=1; n<6; n++) { cout << "Please enter your test score " << n << endl; cin >> testScores; if (testScores<0 || testScores>100) { cout << "That input is invalid. Score must be between 0 and 100." << endl; break; } } system("PAUSE"); return testScores; } float findHighest() { cout << "Enter test score 1 " << endl; cin >> Score1; cout << "Enter test score 2 " << endl; cin >> Score2; cout << "Enter test score 3 " << endl; cin >> Score3; cout << "Enter test score 4 " << endl; cin >> Score4; cout << "Enter test score 5 " << endl; cin >> Score5; if (Score2>highestScore) highestScore = Score2; if (Score3>highestScore) highestScore = Score3; if (Score4>highestScore) highestScore = Score4; if (Score5>highestScore) highestScore = Score5; return highestScore; } void Curve(Score1,Score2,Score3,Score4, Score5) { findHighest(); float Curve1 = Score1/highestScore; float Curve2 = Score2/highestScore; float Curve3 = Score3/highestScore; float Curve4 = Score4/highestScore; float Curve5 = Score5/highestScore; cout << "The curves for each test score are : " << endl; cout << " " << Curve1 << Curve2 << Curve3 << Curve4 << Curve5 << endl; return ; }``````

Last edited on
I'd suggest re-reading whatever source material you used to come up with this program because there are major errors in that speak to a fundamental lack of understanding in general. While a lot of the code is valid, I'm not sure how you got it while having no understanding of the basic structure of a C++ program. From everything that I have EVER seen, you absolutely MUST use main to at least start your program as that is the function that is called by the OS when the program actually starts. Don't believe me? Try commenting out the entire Curve() function and running it. I'm not trying to be harsh, just trying to convey the need to walk before you run, especially when learning something like C++.
closed account (Ebf21hU5)
If I had no understanding of the basic structure of a program I wouldn't have been able to write as much of the code as I have let alone have any of it be valid. I'm not trying to be harsh either. Thank you for your input but I posted this program for assistance not for an opinion.
Specifically, for console applications, main() is defined as the entry-point to the application (where execution begins), and when execution reaches the end of main() execution then ends. In the code you posted, this is the entirety of what actually happens when your application is run:

1. Execution begins at the entry point, main(), defined as:
 ``1234`` ``````int main() { return 0; }``````

2. Main immediately returns 0, as it says, ending the main() function.
3. Execution terminates, as it has reached the end of the main() function. No other functions are called nor run.

In order for other code to be run you need to call other functions from inside main() or do something else which passes execution to elsewhere in the code, which you never do.

Some other problems I see:

 ``12`` ``````float Score1, Score2, Score3, Score4, Score5; float highestScore = Score1;``````

The definition of highestScore makes no sense, because at that point Score1 has no definition. You are assigning highestScore to something completely undefined. You should just leave it undefined in that definition, and assign highestScore to something after the other variables actually have a definition of their own. On top of that, using global variables (Variables which are defined outside of functions, classes or namespaces) is generally a very bad practice. You should make a habit of defining them inside the function, class or namespace ("scope") where they are relevant.

Some of your fundamental understandings of the language were flawed when you wrote this, although not horribly so. I'd recommend doing a little bit more reading on the basics and then giving it another shot.

edit: If you're going to just say "No I'm not wrong I'm right!" when asking for help, I'd recommend you not bother asking in the first place.
Last edited on
Topic archived. No new replies allowed.