If if clause else else clause int car

  • Slides: 14
Download presentation

อยาลม {…} ! If (เงอนไข ( { // if clause } else { //

อยาลม {…} ! If (เงอนไข ( { // if clause } else { // else clause } int car. Doors, driver. Age; float premium, monthly. Payment; …… if ((car. Doors == 4) && (driver. Age > 24) { premium = 650. 00; cout << “ LOW RISK “; } else { premium = 1200. 00; cout << “ HIGH RISK “; } monthly. Payment = premium / 12. 0 + 5. 00; …………… 8

ไมตองใส {…} (Omit Braces) เฉพาะกรณเมอม คำสงเดยว (single statement) เชน if (last. Initial <= ‘K’)

ไมตองใส {…} (Omit Braces) เฉพาะกรณเมอม คำสงเดยว (single statement) เชน if (last. Initial <= ‘K’) volume = 1; Else volume = 2; Cout << “Volume#” << volume << “ of NYC phone book”; 9

รปแบบ ของโครงสรางแบบทางเลอก หลายทางเลอก รปแบบ : if if (condition 1( statement 1; else if (condition

รปแบบ ของโครงสรางแบบทางเลอก หลายทางเลอก รปแบบ : if if (condition 1( statement 1; else if (condition 2( statement 2; : : else if (condition n( statement n; else statement; 12

ตวอยาง ของโครงสรางแบบทางเลอก if หลายทางเลอก */ increment mum-pos, num_neg, or num_zero depending on x/* if

ตวอยาง ของโครงสรางแบบทางเลอก if หลายทางเลอก */ increment mum-pos, num_neg, or num_zero depending on x/* if (x > 0( num_pos = num_pos + 1; else if (x < 0( num_neg = num_neg + 1; else num_zero = num_zero + 1; 13

Computer Programming Design 14

Computer Programming Design 14