zoukankan      html  css  js  c++  java
  • if语句的选择结构

    #include<iostream>
    using namespace std;
    int main()
    {
        int grad;
        cout<<"请输入你要查询的成绩:"<<endl;
        cin>>grad;
        if(grad>100)
            cout<<"您输入的数据错误";
        else if(grad>=90&&grad<=100)
            cout<<"A";
        else if(grad>=80&&grad<90)
            cout<<"B";
        else if(grad>=70&&grad<80)
            cout<<"C";
        else if(grad>=60&&grad<70)
            cout<<"D";
        else
            cout<<"E";
    }

    ————————————————————————————————————

    嵌套的语句——查询成绩

    #include<iostream>
    using namespace std;
    int main()
    {
        int grad;
        cout<<"请输入你要查询的成绩:"<<endl;
        cin>>grad;
        if(grad>100||grad<0)
            cout<<"您输入的数据错误";

        else if(grad<60)
            cout<<"E";
        else
        {
            if(grad<70)
                cout<<"D";
            else
            {
                if(grad<80)
                    cout<<"C";
                else
                {
                    if(grad<90)
                        cout<<"B";
                    else
                        cout<<"A";
                }
            }
        }

    }

  • 相关阅读:
    Java的字符串及格式化输入输出
    Java的数据类型与类型转换
    java基本程序
    svn基础入门
    github基础入门笔记
    git基础入门笔记
    linux基础入门笔记
    二、FreeMarker 模版开发指南 第二章 数值和类型
    【CodeForces】[599B]Spongebob and Joke
    【CodeForces】[612B]HDD is Outdated Technology
  • 原文地址:https://www.cnblogs.com/ywj2013/p/3137305.html
Copyright © 2011-2022 走看看