⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 input.cpp

📁 数据结构c++语言描述 Borland C++实现
💻 CPP
字号:

#include <iostream.h>


template<class T>
bool Input(T& x)
{// Input a nonnegative value.
   int NumOfAttempts = 3;

   // try at most NumOfAttempts times
   for (int i = 0; i < NumOfAttempts; i++) {
      cout << "Enter a nonnegative value" << endl;
      cin >> x;
      if (x >= 0) return true;
      cout << x << " is not nonnegative" << endl;
      }
   // did not get nonnegative value
   cout << "Sorry, you get only "
        << NumOfAttempts << " chances."
        << endl;
   return false;
}


void main()
{// Test Input.

int a;
if (Input(a)) cout << "The number is " << a << endl;
else cout << "Did not get a nonnegative number" << endl;
}

⌨️ 快捷键说明

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