首页 > 代码库 > if else与switch case
if else与switch case
//if elese推荐使用区间判断
//bool a = true;
//double salay = 5000;
//Console.WriteLine("请输入对李四的年终评级");
//string level = Console.ReadLine();
//if (level=="A"){
// salay += 500;
//}else if(level=="B"){
// salay += 200;
//}else if(level=="C"){
//}else if(level=="D"){
// salay -= 200;
//}else if(level=="E"){
//salay-=500;
//}
//else
//{
// Console.WriteLine("输入有误,请重新输入");
// a = false;
//}
//if (a) {
// Console.WriteLine("李四明年的工资是{0}", salay);
//}
//Console.ReadKey();
/*
switch(变量或者表达式的值){
case 值1:要执行的代码;
break;
case 值2:要执行的代码;
break;
case 值3:要执行的代码;
break;
....................
default:要执行的代码;
break;
}
*/
//case推荐使用定值判断
bool b = true;
double salay = 5000;
Console.WriteLine("请输入对李四的年终评级");
string level = Console.ReadLine();
switch(level){
case "A": salay += 500;
break;
case "B": salay += 200;
break;
case "C":break;
case "D": salay -= 200;
break;
case "E": salay -= 500;
break;
default: Console.WriteLine("您输入的有误,请重新输入");
b = false;
break;
}
if (b){
Console.WriteLine("李四明年的工资是{0}", salay);
}
Console.ReadKey();
if else与switch case