ex4_02.cpp

来自「一本语言类编程书籍」· C++ 代码 · 共 26 行

CPP
26
字号
// Exercise 4.2 Using nested ifs and a logical && to check the value of an integer.

#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int main() {
  int value = 0;

  cout << "Please enter an integer between 1 and 100: ";
  cin >> value;
  cout << endl;

  if ((value >= 1) && (value <= 100)) {
    if (value > 50)
      cout << "The integer is greater than 50." << endl;
    else if (value < 50)
      cout << "The integer is less than 50." << endl;
    else
      cout << "The integer you entered is 50." << endl;
  }
  else
    cout << "The integer is not between 1 and 100." << endl;

  return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?