意外错误,不知道为什么
Unexpected errors, not sure why
我似乎无法让我的代码正常运行。我收到错误消息
"错误 1错误 C2078:初始值设定项过多,行:17 列:1"
和
"错误 2 智能感知:预期为')"行:17 通信:21"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
void getScore(int &, int &, int &, int &,int &);
void calcAverage(int, int, int, int, int);
int findLowest(int, int, int, int, int);
int main()
{
int num1, num2, num3, num4, num5;
string response;
getScore(num1, num2, num3, num4, num5);
int findlowest(num1, num2, num3, num4, num5);
//calcAverage(num1, num2, num3, num4, num5);
cout << "Are there any more test scores?" << endl;
cin >> response;
cout << endl;
if (response == "yes")
{
getScore(num1, num2, num3, num4, num5);
//calcAverage(num1, num2, num3, num4, num5);
}
system("pause");
return 0;
}
void getScore(int &num1, int &num2, int &num3, int &num4, int &num5)
{
cout << "What was your score for the first test?" << endl;
cin >> num1;
cout << endl;
if (num1 < 1 || num1 > 100)
{
cout<<"Scores must be between 1 and 100, re-enter the score" << endl;
cin >> num1;
}
cout << "What was your score for the second test?" << endl;
cin >> num2;
cout << endl;
if(num2 < 1 || num2 > 100)
{
cout<<"Scores must be between 1 and 100, re-enter the score" << endl;
cin >> num1;
}
cout << "What was your score for the third test?" << endl;
cin >> num3;
cout << endl;
if(num3 < 1 || num3 > 100)
{
cout<<"Scores must be between 1 and 100, re-enter the score" << endl;
cin >> num1;
}
cout << "What was your score for the fourth test?" << endl;
cin >> num4;
cout << endl;
if(num4 < 1 || num4 > 100)
{
cout<<"Scores must be between 1 and 100, re-enter the score" << endl;
cin >> num1;
}
cout << "What was your score for the fifth test?" << endl;
cin >> num5;
cout << endl;
if(num5 < 1 || num5 > 100)
{
cout<<"Scores must be between 1 and 100, re-enter the score" << endl;
cin >> num1;
}
}
int findLowest(int num1, int num2, int num3, int num4, int num5)
{
int lowest;
lowest = num1;
if (num2 < lowest)
{
lowest = num2;
}
else if (num3 < lowest)
{
lowest = num3;
}
else if (num4 < lowest)
{
lowest = num4;
}
else if (num5 < lowest)
{
lowest = num5;
}
cout << "the lowest test score is " << lowest << endl;
return lowest;
}
void calcAverage(int num1, int num2, int num3, int num4, int num5)
{
int findLowest(int, int, int, int, int);
int lowest;
double average;
findLowest(num1, num2, num3, num4, num5);
cout << lowest << endl;
average = (((float)num1 + num2 + num3 + num4 + num5) - lowest) / 4.0;
cout << showpoint << setprecision(8) << average << endl;
}
Cnange 此语句
int findlowest(num1, num2, num3, num4, num5);
自
int lowest = findLowest(num1, num2, num3, num4, num5);
或干脆作为
findLowest(num1, num2, num3, num4, num5);
因为您不使用返回值。
函数的名称也是 findLowest
.
还有这部分代码
cout << "Are there any more test scores?" << endl;
cin >> response;
cout << endl;
if (response == "yes")
{
getScore(num1, num2, num3, num4, num5);
//calcAverage(num1, num2, num3, num4, num5);
}
没有任何意义。
函数 findLowest 也是错误的。它找不到最低的。例如,当 num1, num2, num3, num4, num5 相应地具有 balues 5, 4, 3, 2, 1 时的情况。
甚至函数 calcAverage 也是错误的,因为它使用了未初始化的变量 lowest。
应该有
int lowest = findLowest(num1, num2, num3, num4, num5);
但是,由于函数 findLowest 的设计不佳,有关最低数字的消息将被输出两次。
另请注意,您将函数定义为int findLowest(int, int, int, int, int);带"L"你用int findlowest(num1, num2, num3, num4, num5);带"L":)的函数名称不同。
相关文章:
- 我正在使用嵌套的while循环来解析具有多行的文本文件,但由于某种原因,它只通过第一行,我不知道为什么
- 我不知道为什么这段代码会让核心被转储?
- 反转字符串.不知道为什么这个逻辑是错误的.C++
- 没有函数模板的实例与我不知道为什么的参数列表匹配
- if-else 语句仅按特定顺序工作,我不知道为什么
- DirectX 11 引擎在第三次代码改进后没有突然运行,我不知道为什么
- 函数抛出seg错误,我不知道为什么
- 我不知道为什么复制构造函数的调用在 c++ 中不稳定
- 随着时间的推移,我的程序越来越慢,我不知道为什么.内存泄漏
- 分段故障(核心转储)-不知道为什么
- "错误:在'.标记'之前出现预期的主表达式,我不知道为什么
- 我正在制作c ++代码,但发生错误我不知道为什么
- std::cout << glGetString(GL_RENDER) << std::endl;抛出错误但不GL_Renderer或GL_Verision,我不知道为什么?
- 不知道为什么它不会停止循环
- 我的Arduino串行命令行不起作用,我不知道为什么
- 我正在编写一个拆分为 3 的合并排序,我不知道为什么它不起作用
- C++单例模式代码无法运行,不知道为什么?
- 为什么我的结果中有 0?我不知道它从哪里来
- 我不知道为什么我的矢量无法推回
- 罗马数字输出C++总是"-858993460",不知道为什么?