大家好!今天为大家带来一个使用for语句的小游戏!
代码如下:
#include<iostream> #include<cstdlib> #include<ctime> #include<Windows.h> using namespace std; int main() { int a,b,jq=1000,j,s; cx: cout<<"-------------------------------"<<endl; cout<<" 抽奖系统"<<endl; cout<<" "<<endl; cout<<" "<<endl; cout<<" ———————————————"<<endl; cout<<" |你现有金额是:"; if(jq>=1000) cout<<jq<<" |"<<endl; else cout<<jq<<" |"<<endl; cout<<" |一百块一次,赢了得一千!!!|"<<endl; cout<<" ———————————————"<<endl; cout<<" "<<endl; cout<<"-------------------------------"<<endl; cout<<"1.START"<<endl; cout<<"2.OVER"<<endl; cout<<"请输入:"; cin>>j; system("cls"); if(j==1) { cx2: cout<<"你现有金额是:"; if(jq>=1000) cout<<jq<<endl; else cout<<jq<<endl; cout<<"请输入1~100的数字:"; cin>>a; srand(time(0)); b=rand()%(100-1+1)+1; if(a==b) { system("cls"); cout<<"恭喜你,中奖1000元"<<endl<<endl; cout<<"要再来吗?"<<endl; cout<<"1.要"<<endl; cout<<"2.不要"<<endl; jq+=900; cin>>s; if(s==1) { if(jq>=100) { system("cls"); goto cx2; } if(jq==0) { cout<<"余额不足!"<<endl; Sleep(1000); cout<< "重开吧!"<<endl; Sleep(1000); cout<<"孩子!"<<endl; Sleep(1200); cout<<"菜就多练!!!"<<endl; } } else { cout<<"再见!"; return 0; } } else { system("cls"); cout<<"没中奖,中奖号码是:"<<b<<endl; cout<<"你的号码是:"<<a<<endl<<endl; cout<<"要再来吗?"<<endl; cout<<"1.要"<<endl; cout<<"2.不要"<<endl; jq-=100; cin>>s; if(s==1) { if(jq>=100) { system("cls"); goto cx2; } if(jq==0) { cout<<"余额不足!"<<endl; Sleep(1000); cout<< "重开吧!"<<endl; Sleep(1000); cout<<"孩子!"<<endl; Sleep(1200); cout<<"菜就多练!!!"<<endl; } } else { cout<<"再见!"; return 0; } } } if(j==2) { cout<<"再见!"; return 0; } }