C ++:只允许数字作为输入

问题描述

我想在下面的代码中屏蔽所有要输入的字母,您能帮我吗?

#include <iostream>
using namespace std;

int main()
{
cout<<"To close this program you need to type in -1 for the first input"<<endl;
int m,n;
do{

 int counter1 = 0;
 int counter2 = 0;
 cout<<"Now you need to input two seperate natural numbers,and after that it calculates the difference of both numbers factors!"<<endl;

 cout<<"First Input"<<endl;
 cin>>m;
 if(m==-1){
    break;
 }
 cout<<"Second Input"<<endl;
 cin>>n;
if(m<0 or n<0){
    cout<<"ERROR - Only natural numbers are allowed!"<<endl;
}
else{
...

程序的其余部分仅仅是数学。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)