ユーザーに数字を尋ねるプログラムを作成する必要があり、ゼロを入力するとゼロを入力したことが出力され、負の数または正の数を入力すると、負または正のいずれかを入力したことが出力されます。正数。文字やコンマなどを受け入れないようにしています。しかし、これを小数を受け入れないようにする方法がわかりませんか? どうすればこれを行うことができますか?cplusplus.com 以外の適切な C++ リファレンスを含む適切なサイト
#include <iostream>
#include <string>
#include <limits>
#include <cmath>
#include <iomanip>
#include <cstdlib>
using namespace std;
int getInt()
{
int choice=0;
while (!(cin >> choice))
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(),'\n');
cout << "Please input a valid integer: " << '\n';
}
return (choice);
}
int print_zero()
{
cout << "The number you entered is a zero. " << '\n';
return 0;
}
int print_negative()
{
cout << "You entered a negative number. " << '\n';
return 0;
}
int print_positive()
{
cout << "You entered a positive number. " << '\n';
return 0;
}
int main ()
{
cout << "your number please:-" << '\n';
int choice = getInt();
if (choice == 0)
{
print_zero();
}
if (choice < 0)
{
print_negative();
}
if (choice > 0)
{
print_positive();
}
cout << endl << "All done! Nice!!" << endl;
return 0;
}