繁体   English   中英

我怎样才能打电话给我的 function 让这个程序计算成绩?

[英]How can I call my function to make this program work to calculate grades?

#include <iostream>

using namespace std;
int grade_calculation (int grade_input){
    if ( grade_input >= 100 && grade_input <= 90){
        cout << 'A';
    } else if (grade_input >= 89 && grade_input <= 80){
        cout << 'B';
    } else if (grade_input >= 79 && grade_input <= 70){
        cout << 'C';
    } else if (grade_input >= 69 && grade_input <= 60){
        cout << 'D';
    } else if (grade_input >= 59 && grade_input <= 0){
        cout << 'F';
    } else {
        cout << "NOT VALID.";
    }
}

int main()
{
    int score = 100;
    int grade_input;
    cout << "Enter a grade: ";
    cin >> grade_input;
    while (grade_input != score){
        cout << "Enter a new grade: ";
        cin >> grade_input;
        grade_calculation(grade_input);
        
    } cout << grade_input;
    return 0;
}

如何正确使用while循环向用户询问字母然后output相应的等级? 除了使用“grade_calculation (grade_input)”之外,还有其他调用 function 的方法吗?

if ( grade_input >= 100 && grade_input <= 90)

这意味着:如果等级高于 100 且等级低于 90 没有满足这个条件的等级。 你可能想要:

if ( grade_input <= 100 && grade_input >= 90)

即:如果 grade 低于或等于 100 且 grade 等于或高于 90

然后,以类似的方式更改所有其他条件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM