栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

c++ if语句

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

c++ if语句

1.单行if语句

#include
using namespace std;
int main()
{
    //选择结构if 单行if语句
    //用户输入一个分数,如果高于500,考上一本并且在屏幕输出

    //1.用户输入分数

    int score = 0;
    cout << "请输入一个分数:" << endl;
    cin >> score;


    //2.打印用户输入分数

    cout << "你输入的分数是:" << score << endl;

    //3.判断分数是否大于500,如果大于就输出

    if (score > 500)
    {
        cout << "恭喜你考上了一本" << endl;
    }








    system("pause");
    return 0;

}

2.多行if语句

#include
using namespace std;
int main16()
{
    //多行if语句
    //如果大于等于500考上,如果小于500未考上,都打印出来

    //1.输入考上分数

    int score = 0;
    cout << "请输入你的分数:" << endl;
    cin >> score;

    //2.显示用户输入的分数

    cout << "你的分数是:" << endl;

    //3.如果考上打印考上一本,如果没考上打印没考上

    if (score >= 500)
    {
        cout << "恭喜考上一本大学" << endl;
    }

    else
    {

        cout << "你没考上一本" << endl;
    
    }







    system("pause");
    return 0;

}

3.多条件if语句

#include
using namespace std;
int main()
{
	//选择结构 多条件if语句
	

	//1.提示用户输入分数

	int score1 = 0;
	cout << "请输入你的分数:" << endl;
	cin >> score1;
	cout << "你的分数是:" << score1 << endl;

	//2.判断分数
	if (score1 >= 600)
	{
		cout << "恭喜你考上一本大学" << endl;
	}
	else if (score1 >= 500)
	{
		cout << "恭喜你考上了二本大学" << endl;
	}
	else if (score1 >= 400)
	{
		cout << "恭喜你考上三本大学" << endl;
	}
	else if (score1 < 400)
	{
		cout << "恭喜你没有大学,只能读本科了" << endl;
	}
	

	else
	{
		cout << "请不要乱输入" << endl;
    
	}
	system("pause");
	return 0;

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/857316.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号