循环问题 [英] Loop Problem

查看:109
本文介绍了循环问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我还是新手,所以请耐心等待......

我对以下代码有疑问:


#include< iostream>

#include< string>


使用命名空间std;


双重测试;


int main()

{


do

{

cout<< 测试数字是否介于0和1000之间: << endl;

cin>>测试;

if(test> = 1000)

{

cout<< 数字大于1000 !!! << endl;

}

else if(test< = 0)

{

cout<< 这个数字不到0 !!! <<结束;

}

}

while((test> = 1000)||(test< = 0));

cout<< 以下数字介于0和1000之间: <<测试<< endl;

cout<< endl;

cout<< "完成" <<结束;

返回0;


}


如果用户意外输入一个字母而不是一个数字,程序疯了!


如何解决这个可能的用户输入错误?


谢谢,


Terence

Ok, I''m still new at this, so bear with me...
I have a question with regards to the code below:

# include <iostream>
# include <string>

using namespace std;

double test;

int main()
{

do
{
cout << "Test to see if a number is between 0 and 1000:" << endl;
cin >> test;
if (test >= 1000)
{
cout << "NUMBER IS GREATER THAN 1000!!!" << endl;
}
else if (test <= 0)
{
cout << "THE NUMBER IS LESS THAN 0!!!" << endl;
}
}
while ((test >= 1000) || (test <= 0));
cout << "The following number is between 0 and 1000: " << test << endl;
cout << endl;
cout << "Done" << endl;
return 0;

}


If the user "accidentally" enters a letter instead of a number, the program goes nuts!!!

How do I account this possible user entry error?

Thanks,

Terence

推荐答案

我也在死这个...我已经构建了一个程序,如果用户输入的值无效,它将在循环中包含用户(任何小于0的数字,要离开循环,他们必须输入正确的值,或者一封信......这封信也会让我的程序变得坚固......!


好问题!
I''m dying on this one too... I''ve built a program that will contain the user in a loop if they enter an invalid value (any number less than 0), to get out of the loop they have to enter the correct value, or a letter... the letter will make my program go nuts too..!

Good question!


男人阅读了如何发布和学习 INDENT 你的代码!!!

真的很难理解
Man read how to post and learn to INDENT your code!!!
its realy hard to understand


plz清楚地解释你对你的预期的期待!
plz explain clearly what u r expecting from ur prog!


这篇关于循环问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆