实例 C++ else if 语句

x
 
#include <iostream>
using namespace std;
int main() {
  int time = 22;
  if (time < 10) {
    cout << "Good morning.";
  } else if (time < 20) {
    cout << "Good day.";
  } else {
    cout << "Good evening.";
  }
  return 0;
}
                    

输出结果

Good evening.