这是我在网上找的一个九阳至尊 剪刀石头布布的C语言小游戏,可是我自己照抄在电脑上却总是有错,求助大神!!!

C语言初学者,练习写一个剪刀石头布的程序,能运行但缺少输和平局的情况,请各位帮忙看看_百度知道
C语言初学者,练习写一个剪刀石头布的程序,能运行但缺少输和平局的情况,请各位帮忙看看
#include&stdio.h&
#include&stdlib.h&
#include&time.h&
int main(void)
printf(&欢迎来到猜拳小游戏,请选择你要出的手势:\n&);
printf(&a剪刀\nb石头\nc布\n&);
我有更好的答案
你赢了!\n&& computer==2)//都出石头printf(&quot,&break.#include&player););).baidu.com/zhidao/wh%3D600%2C800/sign=e4a90816b4ebbac79f3df8dcd1b8bfc2.jpg" esrc="http://a.电脑赢了!\n&);else if (player==65 &&computer = rand()%3+1; // 产生随机数,得到电脑出拳printf(&电脑出了&);switch (computer){case 1:printf(&quot.h&#include&,&剪刀\n&平手!\n&);printf(&\n&);}return 0;}<img class="ikqb_img" src="http://a.hiphotos,请重试://a;srand ((unsigned)time(NULL)); computer==3)//石头——布printf(&%c&);平手!\n&);else if (player==67 &&amp!\n&);if(player&else if (player==66 & computer==1)//石头——剪刀printf(&你赢了!\n&);else if (player==67 &&)#include&if (player==65 || player==97)printf(&你出了剪刀,&);else if (player==66 || player==98)printf(&你出了石头,&);else if (player==67 || player==99)printf(&你出了布
if(player&67)player-=32;这个是什么意思?
采纳率:83%
来自团队:
为您推荐:
其他类似问题
&#xe675;换一换
回答问题,赢新手礼包&#xe6b9;
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。C语言实现小游戏(二)——剪刀石头布
#include&stdio.h&
printf(&*************欢迎进入石头剪刀布游戏************\n&);
printf(&*******************1.start&********************\n&);
printf(&*******************0.exit &********************\n&);
printf(&***********************************************\n&);
int main()
int input = 1;
char ch[10];
int n = 0;
int b = 0;
int i = 0;
int j = 0;
int k = 0;
int a = 0;
while (input)
printf(&请选择&&);
scanf(&%d&, &input);
switch (input)
{for (i = 0; i & 3; i++)
srand((unsigned int)time(NULL));
n = rand() % 3;
printf(&请出石头-剪刀-布\n&);
scanf(&%s&, ch);
if (strcmp(ch, &石头&) == 0)
else if (strcmp(ch, &剪刀&) == 0)
else if (strcmp(ch, &布&) == 0)
if (b == n)
printf(&平局\n&);
if ((b == 0) && (n == 1))
printf(&恭喜你赢了\n&);
else if ((b == 0) && (n == 2))
printf(&很遗憾你输了\n&);
else if ((b == 1) && (n == 0))
printf(&很遗憾你输了\n&);
else if ((b == 1) && (n == 2))
printf(&恭喜你赢了\n&);
else if((b == 2) && (n == 0))
printf(&恭喜你赢了\n&);
printf(&很遗憾你输了\n&);
if (j == 2)
if (a == 2)
if (j == 2)
printf(&恭喜你这一局赢了\n&);
else if (a == 2)
printf(&很遗憾这一局你输了\n&);
else if (k == 3)
printf(&这局是平局\n&);
else if ((k==2)&&(a==1))
printf(&很遗憾这一局你输了\n&);
else if ((k == 2) && (j == 1))
printf(&恭喜你这一局赢了\n&);
printf(&退出游戏\n&);
system(&pause&);
system(&pause&);c语言剪刀石头布小游戏_百度知道
c语言剪刀石头布小游戏
程序要提示用户 输入“ (J)iandao, (S)hitou, hu(B)u :”。
用户可以输入J、S、B三个字符中的一个。如果用户输入不是 J、 S、 B 其中之一,报错: “选择错误!” 。
电脑要能随机出其中的一个。
显示用户出什么,电脑出什么,谁赢了,或平局。
我有更好的答案
#include &stdio.h&#include &stdlib.h&#include &time.h&int main() {
//表示选择的是哪个人 int a,b;
//分别表示人和电脑 printf(&(J)iandao, (S)hitou, hu(B)u :&#92;n&); scanf(&%c&,&m); if(m!=&#39;J&#39; && m!=&#39;S&#39; && m!=&#39;B&#39;)
printf(&Input error!&#92;n&); else
//分别用0,1,2代表石头,剪刀,布 {
srand(time(NULL));
a = rand()%3;
printf(&人出的是石头&#92;n&);
printf(&人出的是剪刀&#92;n&);
printf(&人出的是布&#92;n&);
b = rand()%3;
printf(&电脑出的是石头&#92;n&);
printf(&电脑出的是剪刀&#92;n&);
printf(&电脑出的是布&#92;n&);
printf(&人赢了!&#92;n&);
else if(a == b)
printf(&平局!&#92;n&);
printf(&电脑赢了!&#92;n&); } return 0;}
采纳率:30%
来自团队:
输入的为%c&#92;n电脑为%c&#92!&stdlib.h&you win, hu(B)u :&);scanf(&%c&,a!&else if(d==3)c=&#39;),&a):puts(&you win!&);case -17;if(a!=&#39;J&#39;&&a!=&#39;S&#39;&&a!=&#39;B&#39;) {puts(&选择错误&);exit(0);}srand(time(0));;printf(&void main(){puts(&time.h&gt:puts(&);computer win!&);case 9;B&#39;n&;#include&case 17;int d=rand()%3+1;if(d==1) c=&#39;J&#39;!&quot:puts(&):(J)iandao,c);switch (c-a){case -8;#include&else if(d==2) c=&#39;S&#39;;case 8:puts(&quot#include&stdio.h&break:puts(&you win!&);case -9:puts(&quot, (S)hitou
各种神奇的答案 都灰常感谢!
#include&stdio.h&#include&stdlib.h&#include&time.h&char sjb();
/* 电脑出拳 */int iswin(char rc,char jc); /* 判断输赢:1|0|-1=人赢|平局|电脑赢 */int main(){ char rc,jc,jx=&#39;Y&#39;;
printf(&(J)iandao, (S)hitou, huo(B)u :&);
scanf(&%c&,&rc);
if(rc&=&#39;a&#39; && rc&=&#39;z&#39;)
if( rc==&#39;J&#39; || rc==&#39;S&#39; || rc==&#39;B&#39; ){
jg=iswin(rc,jc);
printf(&你出了%c,电脑出了%c。&,rc,jc);
switch(jg){
printf(&遗憾,你输了!&#92;n&);
printf(&平局!&#92;n&);
printf(&恭喜,你赢了!&#92;n&);
printf(&选择错误!&#92;n&);
printf(&再来一局?(y/n)&);
getchar();
scanf(&%c&,&jx);
getchar();
if(jx!=&#39;Y&#39; && jx!=&#39;y&#39;)
} return 0;}char sjb(){
srand(time(0)); i=rand()%3; switch(i){ case 0:
c=&#39;J&#39;;
case 1: c=&#39;S&#39;;
case 2: c=&#39;B&#39;; } } /* sjb() */int iswin(char rc,char jc){
if(rc==&#39;J&#39; && jc==&#39;B&#39; || rc==&#39;S&#39; && jc==&#39;J&#39; || rc==&#39;B&#39; && jc==&#39;S&#39; )
jg=1; /* 人赢 */ else if(rc==jc)
/* 平局 */ else
/* 人输 */ } /* iswin */
各种神奇的答案 都灰常感谢!
#include &stdio.h&#include &stdlib.h&#include &time.h&#include &ctype.h&#define RAND(N)
(int)((double)rand() / ((double)RAND_MAX + 1) * N)#define PRINT(msg) fputs(msg, stdout)#define MAN_WIN 1#define COM_WIN 2#define NUL_WIN 3 /* 平手 */void flushinp(void){
while((ch = getchar()) != &#39;&#92;n&#39; && ch != EOF);}char getman(void) {
PRINT(&请您出拳 &&& &);
scanf(&%c&, &man);
flushinp(); /* 清空输入缓冲区残余字符 */
man = tolower(man); } while (man != &#39;j&#39; && man != &#39;s&#39;
&& man != &#39;b&#39; && man != &#39;q&#39;); }char getcom(void) {
com = RAND(3); if (0 == com) { com = &#39;s&#39;; } else if (1 == com) { com = &#39;j&#39;; } else if (2 == com) { com = &#39;b&#39;; } }int judgewin(char man, char com){ if (man == com) {
return NUL_WIN; } else if (
&#39;j&#39; == man && &#39;b&#39; == com
|| &#39;s&#39; == man && &#39;j&#39; == com
|| &#39;b&#39; == man && &#39;s&#39; == com) {
return MAN_WIN; } else {
return COM_WIN; }}void disphand(int hand){ switch(hand) {
case &#39;s&#39;: PRINT(&石头&);
case &#39;j&#39;: PRINT(&剪子&);
case &#39;b&#39;: PRINT(&布&);
default: }}int main(void){ char man,
system(&color 3e&); PRINT(&-----------猜
拳--------------&#92;n&
&玩法: 玩家输入S/s(石头)、J/j(剪刀)、B/b(布),Q/q(退出)。&#92;n&); srand( (unsigned) time(NULL) ); while (1) {
/* 人出拳 */
man = getman();
if (&#39;q&#39; == man) { /* 退出游戏 */
com = getcom(); /* 电脑出拳 */
PRINT(&您出了: &);
disphand(man);
PRINT(&, 我出了: &);
disphand(com);
ret = judgewin(man, com);
if (MAN_WIN == ret) { PRINT(&。 您赢了! 不要骄傲啊。&#92;n&); }
else if (COM_WIN == ret) { PRINT(&。 我赢了! 承让承让。&#92;n&); }
else { PRINT(&。 这次打成平手了!&#92;n&); }
} } PRINT(&谢谢惠顾, 祝您天天开心!&#92;n&); getchar(); return 0;}
各种神奇的答案 都灰常感谢!
其他1条回答
为您推荐:
其他类似问题
您可能关注的内容
剪刀石头布的相关知识
&#xe675;换一换
回答问题,赢新手礼包&#xe6b9;
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。C语言实现最简单的剪刀石头布小游戏示例
转载 & & 作者:e
这篇文章主要介绍了C语言实现最简单的剪刀石头布小游戏,涉及C语言数组、随机数与数值运算等相关操作技巧,需要的朋友可以参考下
本文实例讲述了C语言实现最简单的剪刀石头布小游戏。分享给大家供大家参考,具体如下:
#include&stdio.h&
#include&stdlib.h&
#include&time.h&
/*************\
* 剪刀 石头 布 *
* 最简单小游戏 *
\*************/
int main(void){
char gesture[3][10] = {"scissor","stone","cloth"};
int man, computer, result,
/*随机数初始化函数*/
srand(time(NULL));
computer = rand()%3;
printf("\nInput your gesture 0-scissor 1-stone 2-cloth:\n");
ret = scanf("%d", &man);
if(ret !=1 || man&0 || man&2){
printf("Invalid input!\n");
printf("Your gesture:%s\tComputer's gesture: %s\n",
gesture[man], gesture[computer]
result = (man - computer + 4) %3 -1;
if(result & 0)
printf("YOU WIN!\n");
else if(result == 0)
printf("Draw!\n");
printf("You lose!\n");
PS:游戏使用ctrl+c退出程序。
希望本文所述对大家C语言程序设计有所帮助。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具C语言编写程序:和电脑剪刀石头布 怎么让电脑随机输出数字1、2、3 怎么最后输出“石头”“剪刀”“布”_百度知道
C语言编写程序:和电脑剪刀石头布 怎么让电脑随机输出数字1、2、3 怎么最后输出“石头”“剪刀”“布”
谢谢!输入A代表“剪刀”,B代表“石头”,C代表“布”电脑用1代表“剪刀”,3代表“布”【输入格式】:你输入的拳头是:A【输出格式】:电脑出了石头
你出了剪刀
电脑赢了麻烦了,2代表“石头”
我有更好的答案
switch&&&#include&lt:&&,&&#include&&&&1;&man);&&&&srand((int)time(NULL));switch&&nbsp,对其取余数可以获得固定范围的一个数值这里取0~2,+1之后是1~3;&&&int&main(){&a&=&&电脑出问题了233\n&);&&&&&&&&&&&&&&&&}&&&nbsp,产生不同的种子(如果没有这句,电脑只会出相同的种子;case&&nbsp,也就只会出一个拳头)&nbsp,C代表“布”\n&&&nbsp:电脑出了布\n&);&&&&&&&&&&&&&&&&&&&&default:&&&&&&&&&&&&printf(&&&&&&&&&&2;&&&%&i&printf(&【输出格式】;&switch&&&&&&&&nbsp,3代表“布”\n&&&&&&&&);&&printf(&【输出格式】;&&&&&&&#39;A&#39;;&printf(&你出了剪刀\n&&&&&&&&&&&(man)&{&int&i&);=&3,a;&&&&char&&&&&printf(&&rand()&&(a)&{&time.h&case&nbsp,B代表“石头”;printf(&电脑用1代表“剪刀”;&&&&&%c&&&&&&&&case&&&);&&&printf(&【输出格式】;);&&&&&&&&&&&nbsp:&scanf(&quot:&&&&&&&&nbsp,2代表“石头”;&&&nbsp:电脑出了剪刀\n&quot:你输入的拳头是;&(a)&{&case&&&&&&3;&nbsp:&&printf(&【输入格式】;&&nbsp:&);输入A代表“剪刀”:电脑出了石头\n&&&&&&&&//用时间来获取随机数种子;&&&&&&&&&+&1;//rand()会获得一个0~RAND_MAX之间的整数(基于上面获得的随机数种子)。&stdlib.h&&&&&&&&&&&&&&&case&1:&&&&&&&&&&&&&&&&&&&&printf(&平局\n&);&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&case&2:&&&&&&&&&&&&&&&&&&&&printf(&电脑赢了\n&);&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&case&3:&&&&&&&&&&&&&&&&&&&&printf(&你赢了\n&);&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&default:&&&&&&&&&&&&&&&&&&&&printf(&我傻了你信么233\n&);&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&case&&#39;B&#39;:&&&&&&&&&&&&printf(&你出了石头\n&);&&&&&&&&&&&&switch&(a)&{&&&&&&&&&&&&&&&&case&1:&&&&&&&&&&&&&&&&&&&&printf(&你赢了\n&);&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&case&2:&&&&&&&&&&&&&&&&&&&&printf(&平局\n&);&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&case&3:&&&&&&&&&&&&&&&&&&&&printf(&电脑赢了\n&);&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&default:&&&&&&&&&&&&&&&&&&&&printf(&我傻了你信么233\n&);&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&case&&#39;C&#39;:&&&&&&&&&&&&printf(&你出了布\n&);&&&&&&&&&&&&switch&(a)&{&&&&&&&&&&&&&&&&case&1:&&&&&&&&&&&&&&&&&&&&printf(&电脑赢了\n&);&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&case&2:&&&&&&&&&&&&&&&&&&&&printf(&你赢了\n&);&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&case&3:&&&&&&&&&&&&&&&&&&&&printf(&平局\n&);&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&default:&&&&&&&&&&&&&&&&&&&&printf(&我傻了你信么233\n&);&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&default:&&&&&&&&&&&&printf(&你出问题啦~请输入ABC\n&);&&&&&&&&&&&&&&&&}&&&&printf(&不用客气哦~\n&);};&&);&nbsp#include&stdio.h&&&nbsp
采纳率:86%
来自团队:
为您推荐:
其他类似问题
&#xe675;换一换
回答问题,赢新手礼包&#xe6b9;
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。

我要回帖

更多关于 剪刀石头布家居 的文章

 

随机推荐