在程序中定义一个整型变量,赋予1~100的值。要求用户猜这个数,比较这两个数的大小,把结果提示给用户,直到猜对为止。分别使用while,do...while语句实现。
1 回答
已采纳

xungeer29
TA贡献46条经验 获得超20个赞
#include <iostream> #include<cstdlib> using namespace std; int main() { int a; a=(rand()%100+1); int b; do { cout<<"输入你猜的数:"<<endl; cin>>b; if(b<a) { cout<<"小了"<<endl; continue; } else if(b>a) { cout<<"大了"<<endl; continue; } else { cout<<"猜对了"<<endl; break; } }while(1); return 0; }
- 1 回答
- 1 关注
- 1476 浏览
添加回答
举报
0/150
提交
取消