(c++)无法让 void 函数工作,主.cpp内部的几行也有问题
(c++) Cannot get void functions to work, having trouble with a few lines inside of the main.cpp as well
我在下面输入的代码遇到了一些问题。void 函数似乎很好,但它们不起作用。我不确定我做错了什么,所以任何帮助都值得赞赏。另外,我不知道如何使用 if 语句从两个玩家的文件中提出问题,如下所示。拜托,我必须在 11 月 12 日晚上 3 点上交,任何帮助将不胜感激。我已经工作了 5 个小时了
如果语句在此处向玩家 1 显示奇数个问题,向玩家 2 显示偶数个问题,请确保通过调用函数 upDateScoreDouble 为相应玩家添加正确的分数
void getHistory (playerHistory pHist[], int loopy, ifstream& inQuest)
{
int i = 0 ;
loopy = 22 ;
while( i < loopy, i++)
{
inQuest >> pHist[i].alias1 ;
inQuest >> pHist[i].score ;
inQuest >> pHist[i].difficulty ;
inQuest >> pHist[i].date ;
}
return ;
}
void bubblesort (playerHistory pHist[], int length)
{
bool swapped = true;
int j = 0;
int tmp;
while (swapped) {
swapped = false;
j++;
for (int i = 0; i < length - j; i++) {
if (pHist[i].score > pHist[i + 1].score) {
tmp = pHist[i].score;
pHist[i].score = pHist[i + 1].score;
pHist[i + 1].score = tmp;
swapped = true;
}
}
}
return ;
}
///3.3.6 create a loop to call the getQuestion function for each question
for(int loopy=1; loopy<=numQuestions; loopy++)
{
///3.3.6.2 getQuestion function call
getQuestion(gameQ, numQuestions, inQuest) ;
///3.3.6.1 if statement here to display odd number of questions to player1 and even number of questions to player2
///make sure to add the correct score for respective player by calling the function upDateScoreDouble
if(loopy < numQuestions)
{
inQuest >> gameQ[loopy].question;
cout << gameQ[loopy].question ;
cout << gameQ[loopy].answer ;
cout << gameQ[loopy].ans1 ;
cout << gameQ[loopy].ans2 ;
cout << gameQ[loopy].ans3 ;
cout << gameQ[loopy].ans4 ;
}
} ///end of for loop of number of questions
在getHistory
函数中,看起来你想要一个for
循环。
因为表达式i < loopy, i++
计算i < loopy
然后丢弃结果。
相反,循环的条件是i++
,并且由于它在第一次迭代中0
,结果是假的,循环永远不会发生。
阅读有关逗号运算符的更多信息,例如此参考。
你可能想要类似的东西
for (int i = 0; i < 22; ++i) { ... }
相关文章:
- C++从字符串中检索几行
- Eulers 项目问题 no 345 听不懂几行代码
- 如何在几个空行后打印文件中的输出
- CIN 会丢失每行的前几个字符
- 将一个函数名称传递给模板,以使用模板主体内部的几个过载
- 覆盖范围分析一些googletest宏显示在分布在几行上时的覆盖范围不完整 - 原因
- 在C++和Qt中,我如何将这些"#include < Q...>"写到另外几行?
- 记事本 中的正式表达式.如何制作可以在几行中使用的图案
- (c++)无法让 void 函数工作,主.cpp内部的几行也有问题
- 将几行代码写成一行是有益的(就内存和空间复杂性而言)。值得吗?
- iostream正确读取了几行,然后在随后的几行中失败
- gdb的奇怪行为([next]在块代码上向后跳几行)
- C++中几行的含义
- 我似乎无法在qt创建器中打印几行数据。程序覆盖除最后一行之外的所有输出
- 擦除屏幕上的几行,而不是清除整个屏幕
- 什么样的语言特性适合于只有几行不同的类似函数
- c++如何从文件中只读取几行
- 让错误输出包括最后几行代码
- C/C++服务器未发送文件的最后几行
- 为什么当我使用 "randomSelect" 方法替换几行代码时我的程序不起作用