1.1 if else函数 是指如果if的条件成真,执行if函数花括号{}里面的值,否则(即if函数条件不成真)执行else里面的函数 if else的用法 1、if() do ;if()do; 列子: ~~~ if(A> 10) { output < < "Good "; } if(A <5) { output < < "Bad "; } ~~~ 意思的是如果A大于10,则输出good,如果A小于5,则输出bad, 就这个关系~他们是并列的 2、if() do; else do; 列子1: ~~~ if(A> 10) { cout < < "Good "; } else //也就是A <=10的情况~ { cout < < "Bad "; } ~~~ 列子2: ~~~ if(coffee == 'y') { if(donuts == 'y') cout << "We have coffee and donuts."; else cout << "We have coffee, but not donuts"; } else { if(tea == 'y') cout << "We have no coffee, but we have tea, and maybe donuts..."; else cout << "No tea or coffee, but maybe donuts..."; } ~~~ `列子2的意思:如果coffee == 'y',是真的,则执行if{}花括号里面的条件,否则(即coffee == 'y'是假的),执行else{}花括号里面的条件` 3、if()do;elseif do();……else do(); 列子: ~~~ if(A> 90) { cout < < "优 "; } else if(A> 80) //也就是说范围是除了A〉90的情况中,再用条件 { cout < < "良 "; } else if(A> 60) { cout < < "及格 "; } else //就是A小于60的情况了 { cout < < "不及格 "; } ~~~