Linux C一站式学习习题答案 剪刀石头布

来源:互联网 发布:mysql安装失败 编辑:程序博客网 时间:2024/06/05 07:27
#include <stdio.h>#include <stdlib.h>#include <time.h>char arr[3][10] = { "scissor", "stone", "cloth"};int man, comp, result;int man_w = 0;intcom_w = 0;int get_man(){printf("Please chose your gesture: 0-scissor,1-stone,2-cloth\n");scanf("%d",&man);if (man < 0 || man > 2) {man = get_man();}return man;}void game(){srand(time(NULL));//用户选择出什么man = get_man();//电脑随机出comp = rand() % 3;//输出结果printf("your gesteure is %s\n", arr[man]);printf("comp's gesteure is %s\n", arr[comp]);//比较输赢result = (man - comp + 4) % 3 - 1;if (result > 0){printf("You Win!!!\n");man_w++;} else if (0 == result){printf("Draw!!!\n");} else {printf("You Lose!!!\n");com_w++;}return;}int main(){int i, N;printf("please enter the num you want to play:");scanf("%d", &N);for (i = 0; i < N; i++){printf ("************Round %d*************\n", i+1);game();printf ("\n\n");}if (man_w > com_w)printf ("Congratulation!\n%d to %d You WIN!\n",man_w, com_w);else if (man_w = com_w)printf("Draw!!!\n%d to %d\n",man_w, com_w);elseprintf ("Sorry,\n%d to %d You lose!Try again?\n",man_w, com_w);return 0;}
注:转载请注明源地址:http://blog.csdn.net/whorus1/article/list/2,谢谢!
0 0
原创粉丝点击