C++實現猜數字小遊戲
阿新 • • 發佈:2020-10-12
本文例項為大家分享了C++實現猜數字遊戲的具體程式碼,供大家參考,具體內容如下
#include<stdio.h> #include<stdlib.h> #include<iostream> #include<iomanip> //#include<ctime> #include<time.h> using namespace std; int main() { int n; //記錄生成的隨機數,範圍1~100 int g; int count; char c; srand(time(0)); //time(0))返回的是系統的時間(從1970.1.1午夜算起),單位:秒,用作隨機數的種子 cout<<"The torrent of random integer is:"<<time(0)<<endl; do { n=rand()%100+1; count=0; do { cout<<"Please input the number: 1 ~ 100"<<endl; cin>>g; if(g>n) cout<<"Too big!"<<endl; else if(g<n) cout<<"Too small!"<<endl; else cout<<"Right!"<<endl; count++; } while(g!=n && count <= 10); cout<<"The random number is: "<<n<<endl; cout<<"The times you used is:"<<count<<endl; cout<<"Please select if you want to continue the game: (Y/N or y/n)"<<endl; cin>>c; } while (c == 'Y' || c == 'y'); cout<<endl; return 0; system("pause"); }
效果圖:
更多有趣的經典小遊戲實現專題,分享給大家:
C++經典小遊戲彙總
python經典小遊戲彙總
python俄羅斯方塊遊戲集合
JavaScript經典遊戲 玩不停
javascript經典小遊戲彙總
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。