双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

缓存清不了,不知道为什么。

wasdeq7521 wasdeq7521 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include<iostream.h>
#include<stdlib.h>
#include<time.h>
#include<conio.h>
int main(){
int a,char b;
srand((unsigned)time(0));
do{
for(int i=0;i<1;i++){
double ran_num=rand()%10;
do{
cout<<"please enter a number between 1 to 10.\n";
cin.clear();
cin.sync();
cin>>a;
if(a==0){
cout<<"data type error!\n";
b='y';
continue;}
if(a<=0||a>=10){
cout<<"input a number between 1 to 10!\n";
b='y';
continue;}
if(a!=ran_num&&a>ran_num){
cout<<"please input a lesser number\n";}
if(a!=ran_num&&a<ran_num){
cout<<"please input a lager number\n";}
}while(a!=ran_num);
cout<<"Gongratulation!\n";
}
do{
cout<<"\nContinue(yes or no)?\n";
b=getche();
}while(b!='y'&&b!='n');
}while(b=='y');
}


各位大哥可以复制下来,到vc6中运行下试试。由于我才学c++,有很多问题啊~~~~
这个是个简单的猜数游戏,我想控制不能输入字母,但一旦输入字母就会出现无限循环的情况,应该是缓存没清,但我写了cin.clear();cin.sync();的呀,真不知道为什么了~~~~~;还有就是当猜对时,要输入“y”,才会出现 “Gongratulation!”,然后就立马重复游戏了......这个顺序不对啊,应该是出现“Gongratulation!”再问“Continue(yes or no)?”,输入“y”之后才继续游戏啊......
麻烦大家帮帮忙吧,我真不知道是哪出问题了~~~~~谢谢拉~~~~~
...全文
评论 3
收藏 已收藏
分享
返回顶部
wasdeq7521
C++ 语言 65,214 成员 250,514 内容