gpt4 book ai didi

c++ - 错误 C4700 : uninitialized local variable 'lowest' used

转载 作者:太空宇宙 更新时间:2023-11-04 11:50:19 26 4
gpt4 key购买 nike

我有一个我想不通的问题。我对编程有点陌生。这是我写的代码。这是我收到的错误“错误 C4700:使用了未初始化的局部变量‘最低’”,我不确定如何修复它。我也确信有更好的方法来编写这个程序,但这是我必须遵守的要求。如何修复我收到的错误?

#include "stdafx.h"
#include "iostream"
#include <iomanip>

using namespace std;

//Function prototypes
void getScore(int &score);
int findLowest(int score1, int score2, int score3, int score4, int score5, int &lowest);
void calcAverage(int score1, int score2, int score3, int score4, int score5);


int main ()
{
cout<<"Average with Lowest Score Drop by John\n"<<endl;
int score1,
score2,
score3,
score4,
score5,
lowest;

getScore(score1);
getScore(score2);
getScore(score3);
getScore(score4);
getScore(score5);

calcAverage(score1, score2, score3, score4, score5);


cin.get();
cin.get();
return 0;
}

void getScore(int &score)
{

cout << "Please enter 5 test scores between 1 and 100): ";
cin >> score;

while (score <= 0 || score >= 100)
{
cout << "Enter a score values of 0 to 100";
cin >> score;
}
}

int findLowest(int score1, int score2, int score3, int score4, int score5, int &lowest)
{
lowest = score1;
if (score2 < lowest)
lowest = score2;
else if (score3 < lowest)
lowest = score3;
else if (score4 < lowest)
lowest = score4;
else if (score5 < lowest)
lowest = score5;

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

return lowest;
}

void calcAverage (int score1, int score2, int score3, int score4, int score5)

{
int findLowest(int, int, int, int, int, int);
int lowest;
double average;
findLowest(score1, score2, score3, score4, score5, lowest);


average = (((float)score1 + score2 + score3 + score4 + score5) - lowest) / 4.0;
//cout << setw(4);
cout << fixed << showpoint << setprecision(2);
cout <<" With the grade "<<lowest<< " dropped"<<"The average of test scores entered is: " << average << endl;
}

最佳答案

calcAverage 中的

findLowest 原型(prototype)丢失 &:

void calcAverage (int score1, int score2, int score3, int score4, int score5)
{
int findLowest(int, int, int, int, int, int&);
// ^
....
}

实际上,您不需要那个原型(prototype),因为在 main 函数之前已经有相同的原型(prototype)。

关于c++ - 错误 C4700 : uninitialized local variable 'lowest' used,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18627529/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com