按成绩划分high pass、low pass、pass和fail.cpp

/*******************************************
功能:    按成绩划分high pass、low pass、pass和fail
作者:    gnehoaix
时间:    2019\4\22
********************************************/
# include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
	vector <int> num{ 90,65,98,43,64,75 };	
	string result;
	// 利用条件语句
	for (auto j : num)
	{
		 result = j >= 90 ? "high pass" : j >= 75 ? "low pass" : j>= 60 ? "pass" : "fail"; // 使用条件语句 ?:
		 cout << result << endl;
	}
	cout << endl;

	// 利用if语句
	for (auto j : num)
	{
		if (j >= 90)
			cout << "high pass" << endl;
		else if (j < 90 && j >= 75)
			cout << "low pass" << endl;
		else if (j < 75 && j >= 60)
			cout << "pass" << endl;
		if (j < 60)
			cout << "fail" << endl;
	}

	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_36412427/article/details/89462205
今日推荐