求简化~~~~

西木凌萧 2011-09-10 10:37:41
// 程序内容 输入一数,判断是是否为数(包括各种类型的数)是 则输出,否则提示错误从新输入。最后提示是否据需输入Y则总新输入数 输入N结束 若输入其他字符 则提示错误从新输入。//

#include "stdafx.h"
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
char f;
int n;


int i = 0;
while(true)
{
cout<<"please input n:"<<endl;
cin>>n;
if(cin.fail())
{
cout<<"data error!please input the integer:"<<endl;
cin.clear();
cin.sync();
}
else
{
cout<<n<<endl;
while(true)
{
cout<<"Whether to continue to run Y/N"<<endl;
cin>>f;

if(f!='Y'&&f!='N'&&f!='n'&&f!='y')
cout<<"data error!please input the integer:"<<endl;
else if(f == 'n' || f == 'N')
{
i = 1;
break;
}
else if(f == 'y' || f == 'Y')
break;
}

if(i == 1)
break;
}

}
cout<<"the system is over thank for using;"<<endl;
system( "Pause ");
return 0;
}

...全文
94 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
测试NULL 2011-09-16
  • 打赏
  • 举报
回复

/* 帮你简化了一些 ~~ */
#include "stdafx.h"
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
char f;
int n;

do
{
cout<<"please input n:"<<endl;
cin>>n;
if(cin.fail())
{
cout<<"data error!please input the integer:"<<endl;
cin.clear();
cin.sync();
continue;
}
cout<<n<<endl;

cout<<"Whether to continue to run Y/N"<<endl;
cin>>f;
}
while(f == 'y' || f == 'Y');

cout<<"the system is over thank for using;"<<endl;
system( "Pause ");

return 0;
}

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧