c++猜硬币小程序,让其更了解rand函数的用法
#include#include using namespace std; int main() { char yes; char two; int fate; char again; cout << "这是一个猜硬币正反的游戏基于rand()函数,人生有很多决定实在是决定不了不如抛个硬币吧!"<< endl; Sleep(2000); cout << "如果你决定好了那么就开始抛硬币!(Y/N):"; cin >> yes; cout << endl; if(yes == 'Y'||yes == 'y') { againto: cout << "选择硬币正反:"; cin >> two; cout << endl << endl; cout << "命运的齿轮开始旋转....." << endl; Sleep(2000); cout << endl; fate = rand()%2+1; //%是求余符号,2是2个随机数代表正反面 if(fate == 1){ cout << "硬币落地了是<正面>"<< endl; Sleep(1000); } else if(fate == 2){ cout << "硬币落地了是<反面>"<< endl; Sleep(1000); } } else{ cout << "那好吧,再见"; } Sleep(2000); cout << endl; cout << "硬币已经落地,如果硬币的选择是好的那就去做吧!"< > again; cout << endl; if(again == 'Y' || again == 'y'){ goto againto; } int wait; cin >> wait; //等待用户输入后再结束程序 } //我自己觉得程序写的不咋样文案还行吧
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)