最低得分下降平均值

问题描述 投票:-2回答:1

我的程序正在编译,但是我没有得到正确的平均分数。我不确定是否应该保留:最低= findLowest。我得到的平均答案不正确,但是如果我拿走最低的= findLowest,我仍然得到错误的数字。任何帮助将不胜感激!

#include <iostream>
#include <iomanip>
using namespace std;

// Function prototypes go here
void getScore(int &score);
void calcAverage(int, int, int, int, int);
int main()

    {
        int test1, test2, test3, test4, test5;    // 5 user input test scores

        // Inform the user what the program does
        cout << "After you enter 5 test scores, I will drop the lowest \n"
            << "one and find the average of the four highest ones. \n\n";

        // Call getScore once for each test score to be input
        getScore(test1);
        getScore(test2);
        getScore(test3);
        getScore(test4);
        getScore(test5);

        // Call calcAverage to calculate and display the average
        calcAverage(test1, test2, test3, test4, test5);
        return 0;
    }// end of main function

    /*********************************************************************
     *                              getScore                             *
     * This function accepts a user entered score and validates it. The  *
     * score is placed in a reference parameter so that it is stored in  *
     * a memory location belonging to the function that called getScore. *
     *********************************************************************/
    //put code for getScore function here
    void getScore(int &score)
    {
        cout << "Enter score one by one: ";
        cin >> score;

        while (score < 1 || score > 100)
        {
            cout << "ERROR: Please enter Test score values 0 to 100! ";
            cin >> score;
        }

    }

    /***********************************************************
     *                        calcAverage                      *
     * This function determines and prints the average of the  *
     * best 4 out of the 5 scores passed to it as arguments.   *
     ***********************************************************/
    //put code for calcAverage function here
    void calcAverage (int test1, int test2, int test3, int test4, int test5)

    {
        int findLowest(int, int, int, int, int, int);
        int lowest;
        double average;

      lowest = findLowest(test1, test2, test3, test4, test5, lowest);

        average = (((float)test1 + test2 + test3 + test4 + test5) - lowest) / 5.0;
    //Numeric output
    cout << setw(4);
    cout << fixed << showpoint << setprecision(12);
    cout << "The average of the 5 highest test scores entered is: " << average << endl;
    }

    /**************************************************************
     *                          findLowest                        *
     * This function is called by calcAverage to determine which  *
     * of the 5 scores passed to it as arguments is the lowest.   *
     * The lowest score is returned.                              *
     **************************************************************/
    //put code for findLowest function here

    int findLowest(int test1, int test2, int test3, int test4, int test5, int lowest)
    {

    lowest = test1;
    if (test2 < lowest)
    lowest = test2;
    else if (test3 < lowest)
    lowest = test3;
    else if (test4 < lowest)
    lowest = test4;
    else if (test5 < lowest)
    lowest = test5;


    cout << "The lowest test score is " << lowest << endl;

    return lowest;
    }
c++
1个回答
0
投票

现在要了解的重要事项是:如果您拿走最低的价格,那么平均的Mang数是4或5?

average = (((float)test1 + test2 + test3 + test4 + test5) - lowest) / 5.0;
© www.soinside.com 2019 - 2024. All rights reserved.