|
![]() | 作者: bailove [bailove]
![]() |
登录 |
#include <stdlib.h> #include <stdio.h> #include <math.h> main() { int a,b,i,c,d,e; char j; static char choice[10]; do { printf("put you want choice si=sinker,sc=scissors or cl=cloth when you input \" count\"\n"); printf("printf result\n"); c=0;d=0;e=0; for (i=1;i<=20;i++) { gets(choice); printf("\n"); if (choice[1]=='i') a=0; else if (choice[1]=='c') a=2; else if (choice[1]=='l') a=1; else if (choice[4]=='t') break; else {printf("you input must get wrong\n");break;} randomize(); b=random(3); if (b==0) printf("however my choice is sinker\t" ); else if (b==1) printf("however my choice is cloth\t"); else printf("however my choice is scissors\t"); if (fabs(b-a)==1) if (b>a) {printf("so you loss\n"); c++; } else {printf("so you win\n"); d++; } if (fabs(b-a)==2) if (b>a) {printf("so you win\n" ); d++; } else {printf("so you loss\n"); c++; } if (fabs(b-a)==0) {printf("we are deuce\n"); e++; } strcpy(choice," "); } printf("you have play %d times\n",i-1); printf("you win %d times in the lump\n",d); printf("you loss %d times in the lump\n",c); printf("you are deuce %d times in the lump\n",e); if (d>c) printf("the finally result is you win this games\n"); else if (d==c)printf("the finally result you are deuce this games\n"); else printf("the finally result is you loss this games\n"); printf("\n"); printf("if you want play the game again input \"y\"\t"); scanf("%c",&j); } while (j=='y'||j=='Y'); } 这个锤子.剪刀.布程序只能运行一次.但执行do -while时gets(choice)好象不被执行.用了step by step是直接跳到gets但没有反应是为什么啊 |
地主 发表时间: 04/03 12:21 |
![]() | 回复: yujinsen [yujinsen] ![]() |
登录 |
去掉static,在试一试 |
B1层 发表时间: 04/03 13:32 |
![]() | 回复: sunyue [sunyue] ![]() |
登录 |
你在gets(choice);前面加上 fflush(stdin); 应该就可以重复使用gets函数了 |
B2层 发表时间: 04/03 14:29 |
![]() | 回复: bailove [bailove] ![]() |
登录 |
但是我用两个for循环的时候却可以是为什么呢? 我回家试试看fflush(stdin); 谢谢~~~ |
B3层 发表时间: 04/03 18:34 |
![]() | 回复: bailove [bailove] ![]() |
登录 |
fflush(stdin); sunyue能问下,这个语句是什么意思啊 |
B4层 发表时间: 04/06 13:10 |
![]() | 回复: sunyue [sunyue] ![]() |
登录 |
flush a stream,在这里stdin是标准输入流(你用的printf/scanf/gets都是standard I/O stream函数)。 建议你找一个MSDN装上,相信会对你写程序有所助益 [此贴被 感觉者(sunyue) 在 04月07日11时27分 编辑过] |
B5层 发表时间: 04/07 09:46 |
![]() | 回复: bailove [bailove] ![]() |
登录 |
但为什么我在用两for的语句却不存在这样的问题啊 用在do while时就出现了问题,加了这函数就得到了解决。fflush(stdin);与解决这个问题有什么联系呢? “MSDN”这看起来好象曾经见过。但想不起来是什么东西 “感觉者”再请你指教下好吗? |
B6层 发表时间: 04/08 17:22 |
![]() | 回复: sunyue [sunyue] ![]() |
登录 |
这个和用哪种循环语句没关系,主要是scanf和getc(gets)一起使用造成的. 所以如果你循环使用scanf/gets,就需要在getc(gets)前把scanf输入的东西清除掉 MSDN是微软给Virual Studio程序开发人员的帮助文件(有光盘的),你也可以直接连到微软的网站上查阅. |
B7层 发表时间: 04/08 18:56 |
![]() | 回复: bailove [bailove] ![]() |
登录 |
感觉者 我能加你QQ吗? 我 的QQ是3685610。加些说明 |
B8层 发表时间: 04/10 12:07 |
|
20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon
粤ICP备05087286号