赞
踩
void thereGame() { while (1) { cout << " StoneScissorsCloth\n-Two wins form three games-\n"; cout << "----------" << endl; cout << " 0.Stone\n 1.Scissors\n 2.cloth\n" << endl; cout << "----------" << endl; int UseNum; int frequency = 0; //种下随机数种子 //srand函数用来设置rand函数 srand((unsigned int)time(NULL)); int PcNum = rand() % 3;// PcNum范围:rand() % n --- [0 , n - 1] cout << "Please select a number at 0-2:" << endl; scanf_s("%d", &UseNum); while (UseNum < 0 || UseNum>2) { cout << "Error!Please re-enter." << endl; cout << "Please select a number at 0-2:" << endl; scanf_s("%d", &UseNum); } getchar();//清空缓存区 switch (UseNum) { case 0: cout << "UseNum is stone." << endl; break; case 1: cout << "UseNum is Scissors." << endl; break; case 2: cout << "UseNum is cloth." << endl; break; } switch (PcNum) { case 0: cout << "Pc is stone." << endl; break; case 1: cout << "Pc is Scissors." << endl; break; case 2: cout << "Pc is cloth." << endl; break; } int winOrFailure = UseNum - PcNum; switch (winOrFailure) { case 0: cout << "Equal." << endl; break; case -1: case 2: cout << "you win." << endl; break; case -2: case 1: cout << "you failure" << endl; break; } cout << "Are you continue?(enter n eixt)." << endl; cout << "Press any key to continue." << endl; char ch = 0; while ((ch = getchar()) != '\n') { if (ch == 'n' || ch == 'N') return; } system("cls");//系统清屏函数, 在 .c文件中可能无法使用 } }
附上运行截图:
思维导图:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。