码迷,mamicode.com
首页 > 编程语言 > 详细

c++程序—选择结构

时间:2020-02-27 23:46:20      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:names   NPU   put   sch   input   ios   pre   iostream   system   

  • if(判断条件){执行语句}
#include<iostream>
using namespace std;
#include<string>

int main()
{
    int score = 0;
    cout << "Input your score,please  :" << endl;
    cin >> score;
    cout << "Your score is " << score << endl;
    if (score >= 512)
    {
        cout << "You will own a good school!" << endl;
    }
    
    system("pause");
    return 0;

}
  • if...else
#include<iostream>
using namespace std;
#include<string>

int main()
{
    int score = 0;
    cout << "Input your score,please  :" << endl;
    cin >> score;
    cout << "Your score is " << score << endl;
    if (score >= 512)
        cout << "You will own a good school!" << endl;
    else
        cout << "see you next year" << endl;

    
    system("pause");
    return 0;

}
  • 多种选择
#include<iostream>
using namespace std;
#include<string>

int main()
{
    float score = 0;
    cout << "Input students‘ score(0 to 100),please  :" << endl;
    cin >> score;
    cout << "score is " << score << endl;
    if (score >= 90)
        cout << "The student‘ score is A" << endl;
    else if(score>=80)
        cout << "The student‘ score is B" << endl;
    else if (score >= 60)
        cout << "The student‘ score is C" << endl;
    else
        cout << "The student‘ score is D" << endl;
    
    system("pause");
    return 0;

}

 

c++程序—选择结构

标签:names   NPU   put   sch   input   ios   pre   iostream   system   

原文地址:https://www.cnblogs.com/hackerteen/p/12375121.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!