c++程序—选择结构

  • 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;

}

 

posted @ 2020-02-27 23:06  Jackie_Wang  阅读(499)  评论(0编辑  收藏  举报