我繼續得到這個錯誤,我已經多次查看了我的代碼,並且我看不到我的錯誤回合。該程序應該有5個用戶輸入一個評分,然後找到最高和最低的輸入,並將它們與平均值一起返回給用戶。錯誤功能太多參數
在此先感謝。
#include <iostream> // whatever this is
#include <iomanip>
using namespace std;
int getValue();
int findLowest();
int findHighest();
double findAverage();
int main(){ // main function
cout << setw(15)<<""<< "Product Review"; // displays this at the top
int ratingOne = getValue();
int ratingTwo = getValue();
int ratingThree = getValue();
int ratingFour = getValue();
int ratingFive = getValue();
int low = findLowest(ratingOne, ratingTwo, ratingThree, ratingFour, ratingFive);
int high = findHighest(ratingOne, ratingTwo, ratingThree, ratingFour, ratingFive);
double average = findAverage(ratingOne, ratingTwo, ratingThree, ratingFour, ratingFive);
cout << "\nThe highest rating received was: " << high;
cout << "\nThe lowest rating received was: " << low;
cout << std::fixed << std::setprecision(2) << "\nThe average rating received among 5 users was: " << average;
}
int getValue(){
int rating;
do {
cout << "\nOn a scale of 1 to 10, how would you rate our product? ";
cin >> rating;
if (rating < 1 || rating > 10) {cout << "\nYou have entered an invalid number. Please try again.";}
} while (rating < 1 || rating > 10);
return rating;
}
int findLowest(){
int low = 11;
if (ratingOne < low) { low = ratingOne }
if (ratingTwo < low) { low = ratingTwo }
if (ratingThree < low) { low = ratingThree }
if (ratingFour < low) { low = ratingFour }
if (ratingFive < low) { low = ratingFive }
return low;
}
int findHighest(){
int high = 0;
if (ratingOne > high) { high = ratingOne }
if (ratingTwo > high) { high = ratingTwo }
if (ratingThree > high) { high = ratingThree }
if (ratingFour > high) { high = ratingFour }
if (ratingFive > high) { high = ratingFive }
return high;
}
double findAverage(){
double average;
average = ratingOne + ratingTwo + ratingThree + ratingFour + ratingFive;
average = average/5;
return average;
}
'findlowest()'不帶任何參數,你用5個參數來回憶它。與'findHighest'和'findAverage'相同。 – Barmar
請編輯您的問題以提供[mcve]。 –
使'ratingOne','ratingTwo','ratingThree','ratingFour'和'ratingOne'全局並且在'main'中調用沒有任何參數的三個函數findLowest,findHighest和findAverage。或者改變函數簽名來接受五個'int'。 –