我正在尝试完成结构练习;



到目前为止,这是我汇总并遇到的问题-不知道为什么我没有得到想要的输出。 (任何帮助将不胜感激!):

//
#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);
}

最佳答案

这个..

void printstudent(studentType student);

不是您如何调用函数(它是函数声明)。

用...替换该行之后
printStudent(student3);
// ^^ name of the function to call
//           ^^ parameter(s) passed to the function

我得到以下输出:
Mike Green7597A

您可能想要添加一些空白并打印其他学生。我建议您学习std::vector和循环以使您的代码更容易。

关于c++ - C++结构练习,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60065456/

10-13 08:15