我试着完成一个结构练习;
姓名(字符串):John Alisa Mike姓氏(string):白棕色绿色课程等级(char):0(待计算)“测试分数(int):8890 75 Lab得分(int):70 64 97
b.执行下列任务:
约翰·怀特分数是:C级考试成绩是: 88分是:70分是:C级考试成绩是:90分是:64个迈克·格林成绩是:一个考试成绩是:75分是: 97按任意键继续。。。
以下是我到目前为止所做的工作--不确定为什么我没有得到预期的输出。(如有任何帮助,将不胜感激!)
//
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
const double testweight = 0.30;
const double labweight = 0.70;
char getGrade(int testScore, int labScore) {
if ((testweight * testScore) + (labweight * labScore) >= 90)
return 'A';
else if ((testweight * testScore) + (labweight * labScore) >= 80)
return 'B';
else if ((testweight * testScore) + (labweight * labScore) >= 70)
return 'C';
else if ((testweight * testScore) + (labweight * labScore) >= 60)
return 'D';
else return 'F';
}
struct studentType
{
string studentFName;
string studentLName;
int testScore;
int labScore;
char grade;
};
void printstudent(studentType student)
{
cout << student.studentFName << " " << student.studentLName
<< "" << student.testScore
<< "" << student.labScore
<< "" << student.grade << endl;
}
int main()
{
studentType student1;
studentType student2;
studentType student3;
student1.studentFName = "John";
student1.studentLName = "White";
student1.testScore = 88;
student1.labScore = 70;
student1.grade = getGrade(student1.testScore, student1.labScore);
student2.studentFName = "Alisa";
student2.studentLName = "Brown";
student2.testScore = 90;
student2.labScore = 64;
student2.grade = getGrade(student2.testScore, student2.labScore);
student3.studentFName = "Mike";
student3.studentLName = "Green";
student3.testScore = 75;
student3.labScore = 97;
student3.grade = getGrade(student3.testScore, student3.labScore);
void printstudent(studentType student);
}发布于 2020-02-04 21:11:45
这个..。
void printstudent(studentType student);不是如何调用函数(它是函数声明)。
将这一行替换为
printStudent(student3);
// ^^ name of the function to call
// ^^ parameter(s) passed to the function我得到以下输出:
Mike Green7597A您可能希望添加一些空白,并打印其他学生。我建议您学习std::vector和循环以简化代码。
发布于 2020-02-04 21:11:36
代码的最后一行是函数声明。这应该是函数调用。用下面代码中的一行或全部行替换它:
printstudent(student1);
printstudent(student2);
printstudent(student3);对于函数调用,您需要function_name,括号中将参数和分号放在末尾。
function_name(argument);https://stackoverflow.com/questions/60065456
复制相似问题