C++入门经典-例3.11-使用if语句来实现根据输入的字符输出字符串

1:代码如下:

// 3.11.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
using namespace std;
void main()
{
    cout<<"输入一个A-D范围内的大写字母作为成绩评价"<<endl;
    int iInput;
    cin >> iInput;
    if(iInput = 'A')
    {
        cout << "very good" <<endl;
        return ;
    }
    if(iInput = 'B')
    {
        cout << "good" <<endl;
        return ;
    }
    if(iInput = 'C')
    {
        cout << "normal" <<endl;
        return ;
    }
    if(iInput = 'D')
    {
        cout << "failure" <<endl;
        return ;
    }
    cout << "input error" << endl;
}
View Code

运行结果:

原文地址:https://www.cnblogs.com/lovemi93/p/7515245.html