gpt4 book ai didi

c++ - 没有得到预期的输出

转载 作者:行者123 更新时间:2023-11-28 00:47:39 24 4
gpt4 key购买 nike

<分区>

我正在写一个家庭作业,要求用户读入一个包含未知数量的 SSN 和成绩的文本文件。然后,程序需要计算最高分、最低分和平均分,然后输出最高分和相关 SSN 以及最低分和平均分。

看似运行正常,但输出全是“0”。

非常感谢任何解决此问题的帮助。

代码:

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>


using namespace std;

int main()
{
string ssn, maxSSN;
int grade = 0, totalGrades = 0, count = 0, maxScore = 0, minScore = 0;
double avgScore = 0;

ifstream inFile;
inFile.open("C:\\lab5a.txt");

if(!inFile)
{
cout << "Error opening the requested file\n\n";
system("pause");
return 101;
}



while (!inFile.eof())
{
if (count == 0)
{
maxScore = grade;
minScore = grade;
}
else
{
if (grade > maxScore)
maxScore = grade;
if (grade < minScore)
minScore = grade;
}
grade += totalGrades;
count++;

}

if (count)
avgScore = totalGrades / count;

cout << "Maximum Score: " << maxScore << " Student SSN:" << maxSSN << "\n";
cout << "Minimum Score: " << minScore << "\n";
cout << "Average Score: " << avgScore << "\n";
// studentFile >> ssn >> grade;

inFile.close();

cout << "\n\n";
system("pause");
return 0;

}

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