trying to calculate and display average of the four highest scores. NEED HELP!!
| jrock (14) | |||
| #include "stdafx.h" #include <iostream> using namespace std; void getScore(int &, int &, int &, int &, int &); void calcAverage(double, double, double, double, double); int findLowest(); int main() { int s1, s2, s3, s4, s5; cout << "I am staring in function main.\n"; getScore(s1, s2, s3, s4, s5); cout << "Now back in main. The 5 test score are: " << endl; cout << s1 << endl << s2 << endl << s3 << endl << s4 << endl << s5 << endl; cout << "Now back in main." << endl; cout << "The average of the 4 highest test scores is: "; calcAverage(s1, s2, s3, s4, s5); cout << s1 << endl << s2 << endl << s3 << endl << s4 << endl << s5 << endl; return 0; } void getScore(int &s1, int &s2, int &s3, int &s4, int &s5) { cout << "Enter 5 test scores: "; cin >> s1 >> s2 >> s3 >> s4 >> s5; // Input Validation// while (s1 < 0 || s1 > 100 && s2 < 0 || s2 > 100 && s3 < 0 || s3 > 100 && s4 < 0 || s4 > 100 && s5 < 0 || s5 > 100) { cout << "Invaild value entered !!" << endl; cout << "Please enter a value between 0 through 100: "; cin >> s1 >> s2 >> s3 >> s4 >> s5; } } void calcAverage(double s1, double s2, double s3, double s4, double s5) { cout << (s1 + s2 + s3 + s4 + s5) / 4 << endl; } | |||
| DiptenduDas (84) | |||
| Hi jrock, I think U should write the problem statement. Gud to see the code. But U can make it better If u would have used the "insert code" button while posting. AnyWay I think If U r wondering why it is not providing the right output the problem lies below:
cout << (s1 + s2 + s3 + s4 + s5) / 4 << endl;U r taking sum of five values, where as dividing it by 4 to get the Average of 5 numbers !!! | |||
| Grey Wolf (637) | |||||||
| jrock Please post questions in one forum only! There are links to a couple of guidance articles at the bottom of this, please read them. jrock wrote (in other forum): | Write a program that calculates the average of a group of test scores, | where the lowest score in the group is dropped. It should use the | following functions: | | a.) voidgetScore() should ask the user for a test score, store it in a | reference parameter variable, and validate it. This function should be | called by main once for each of the five scores to be entered. | | b.) voidcalcAverage() should calculate and display the average of the | four highest scores. This function should be called just once by main, and | should be passed the five scores. | | c.) int findLowest() should find and return the lowest of the five scores | passed to it. It should be called by calcAverage, who uses the function to | determine which of the five scores to drop. | | // Input validation // DO NOT ACCEPT TEST SCORES LOWER THAN 0 OR | HIGHER THAN 100 Part a, says to use the function void getScore() to get a score...
Part b, You would have to do somthing along the line of
part c, you would have somthing like
How To Ask Questions The Smart Way http://www.cplusplus.com/forum/articles/1295/ How to put code into your postings http://www.cplusplus.com/forum/articles/1624/ | |||||||
| PoliticalDestruction (10) | |||
| First, let it be known, mainly to Grey Wolf, being an ass to someone is not the most optimized way to solve a problem. Next, on to helping jrock. Multiple functions isn't necessary for such a small task, you could just stick inside of main.
| |||
| Grey Wolf (637) | |||
| PoliticalDestruction wrote: | First, let it be known, mainly to Grey Wolf, being an ass to someone is not | the most optimized way to solve a problem. Exactly how was I being an ass to someone? | Next, on to helping jrock. Multiple functions isn't necessary for such a | small task, you could just stick inside of main. It may not be necessary but it is what the OP has been asked to do! | |||
| jrock (14) | |||
| thank you for your input about this program..GREY WOLF and POLITICAL DESTRUCTION.. both of you really help me out with this program. | |||
| PoliticalDestruction (10) | |||
| jrock wrote: | thank you for your input about this program..GREY WOLF and POLITICAL | DESTRUCTION.. both of you really help me out with this program. Your welcome. I am glad you asked, it was fun to make this. | |||
This topic is archived - New replies not allowed.
