资源预览内容
第1页 / 共9页
第2页 / 共9页
第3页 / 共9页
第4页 / 共9页
第5页 / 共9页
第6页 / 共9页
第7页 / 共9页
第8页 / 共9页
第9页 / 共9页
亲,该文档总共9页全部预览完了,如果喜欢就下载吧!
资源描述
C语言猜数字游戏重写版缺乏之处还望大家不吝赐教。 #include #include#includestruct right_place int right; int place; int main (void) int creatDialog (int x, int *p ); void rndProduce (int numDft); struct right_place numCompare (int numDft, int numIn); int dialog, quitOrContinue, allQuit; int numDft4, numIn4, result2; struct right_place compareBack; creatDialog (1, NULL); allQuit = 1; while (allQuit = 1) creatDialog (7, NULL); rndProduce (numDft); quitOrContinue = 1; while (quitOrContinue = 1) dialog = 2; while (dialog = 2) creatDialog (2, numIn); dialog = creatDialog (3, numIn); compareBack = numCompare (numDft, numIn); result0 = compareBack.right ; result1 = compareBack.place ; quitOrContinue = creatDialog (4, result); if (quitOrContinue = 2) allQuit = creatDialog (5, numDft); if (quitOrContinue = 3) allQuit = 1; if (quitOrContinue = 4) allQuit = 2; if (allQuit = 2) creatDialog (6, NULL); getchar (); return 0; int creatDialog (int x, int *p) int back; int i; switch (x) case 0: printf (“*n“); break; case 1: creatDialog (0, NULL); printf (“欢送玩猜数字嬉戏!n版本2.0n:andyzhshgn制作日期:2022.9.1n“); creatDialog (0, NULL); printf (“在本嬉戏中,你需要输入四个数字,n然后电脑会给出你猜想的正确状况。“); printf (“电脑会用它之前生成的n四位数与之你的输入比拟,然后告知你“); printf (“你猜对了几个数字,包n括数值和挨次的信息.n“); break; case 2: creatDialog (0, NULL); printf (“请输入你猜想的四位数字(用空格、回车、或Tab隔开):n“); for (i = 0; i 4; i+, p+) scanf (“%i“, p); break; case 3: creatDialog (0, NULL); printf (“你输入的数字是:%i %i %i %i ,确认请输入“1”,重新输入按“2”。n“, *p, *(p + 1), *(p + 2), *(p + 3); scanf (“%i“, return back; break; case 4: creatDialog (0, NULL); printf (“你输入的数字中:n数值和位置都正确的有%i个,n数值正确但位置不正确的有%i个.n“, *p, *(p+1); if (*p) = 4) printf (“恭喜你,答对了!n“); printf (“连续嬉戏吗?连续请输入“1”,退出嬉戏请输入“2”。n“); scanf (“%i“, if (back = 1) return 3; if (back = 2) return 4; else printf (“连续吗?连续请输入“1”,显示正确答案请输入“2”。n“); scanf (“%i“, return back; break; case 5: creatDialog (0, NULL); printf (“正确答案是:%i %i %i %i,再接再厉啊!n“, *p, *(p + 1), *(p + 2), *(p + 3); printf (“连续嬉戏吗?连续请输入“1”,退出嬉戏请输入“2”。n“); scanf (“%i“, return back; break; case 6: creatDialog (0, NULL); printf (“感谢你玩本嬉戏,再见!n按任意键退出n“); break; case 7: creatDialog (0, NULL); printf (“新的嬉戏开头了!GOOD LUCK!n“); break; default: break; void rndProduce (int numDft) int i; srand( (unsigned)time( NULL ) ) ; for ( i = 0; i 4; i+) numDfti = rand () % 10; /printf (“%i %i %i %in“, numDft0, numDft1, numDft2, numDft3); struct right_place numCompare (int numDft, int numIn) int i, j; struct int Dft; int In; flag4 = 1, 1, 1 ,1 ,1, 1, 1, 1 ; struct right_place result = 0, 0 ; for (i = 0; i 4; i+) if (numDfti = numIni) (result.right)+; flagi.Dft = 0; flagi.In = 0; for (i = 0; i 4; i+) for (j = 0; j 4; j+) if (flagi.Dft flagi.Dft = 0; flagj.In = 0; return result;
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号