首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

急求解决!解决方案

2012-02-13 
急求解决!#includestdio.h#includestdlib.h#includetime.hint srand_row()void math(int a,int b)

急求解决!
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int srand_row();
void math(int a,int b);
void main()
{
char x,y;
int num,count1=0,count2=0,count3=0;
do{
printf("你要出的拳是:");
printf("出拳列表:1,布2,石头3,剪刀");
scanf("%c",&x);
srand(time(NULL));
}while(y=='y');
printf("你是否继续(y/n)");
y=getchar();
fflush(stdin);
num=srand_row();
if(math()==0)
{
printf("你赢拉");
count1++;
}
if(math()==1)
{
printf("你打平拉");
count2++;
}
if(math()==2)
{
printf("你输拉");
count3++;
}
printf("你赢拉%d盘,你平拉%d盘,你输拉%d盘",count1,count2,count3);
}
int srand_row()
{
return rand()%3+1;
}
void math(int a,int b)
{
if(a==1&&b==3)
{
return 0;
}
else if(a==3&&b==2)
{
return 0;
}
else if(a==1&&b==2)
{
return 0;
}
else if(a==b&&b==a)
{
return 1;
}
else
{
return 2;
}
}


[解决办法]
比较乱

C/C++ code
#include <stdio.h > #include <stdlib.h > #include <time.h > int srand_row(); int math(int a,int b); void main() {     int nIn;    int nRand = 0;    int count1 = 0;    int count2 = 0;    int count3 = 0;    srand(time(NULL));    do    {         printf("你要出的拳是:");         printf("出拳列表:1,布2,石头3,剪刀");         scanf("%d", &nIn);         getchar();        nRand = srand_row();        if(math(nIn, nRand)==0)         {             printf("你赢拉\n");             count1++;         }         if(math(nIn, nRand)==1)         {             printf("你打平拉\n");             count2++;         }         if(math(nIn, nRand)==2)         {             printf("你输拉\n");             count3++;         }         printf("你是否继续(y/n)");    }while(getchar() == 'y');      printf("你赢拉%d盘,你平拉%d盘,你输拉%d盘",count1,count2,count3); } int srand_row() {     return rand()%3+1; } int math(int a,int b) {     if(a==1&&b==3)     {         return 0;     }     else if(a==3&&b==2)     {         return 0;     }     else if(a==1&&b==2)     {         return 0;     }     else if(a==b&&b==a)     {         return 1;     }     else     {         return 2;     } } 

热点排行