标题:编了个21点游戏 结果错误好多的样子T T求指点
只看楼主
贰贰
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2015-1-9
结帖率:0
已结贴  问题点数:20 回复次数:4 
编了个21点游戏 结果错误好多的样子T T求指点
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int n1=2,n2=2;
int main()
{
    void Game();
    char str[10];
    printf("if you want to start the game,enter start,otherwise log out\n");
    gets(str);
    if(strcmp(str,"start")==0)
        Game();
    else printf("Thank you for your playing!\n");
    return 0;
}
void Game()
{
    void poker(int x);int analyse(int y);int count(int x,int y);
    void Decide(int player,int computer);int Analyse(int y);
    int computer,player,a1,a2,b1,,b2;
    while(n1<=5&&n2<=5)
    {
        a1=rand()%52+1;a2=rand()%52+1;
        b1=rand()%52+1;b2=rand()%52+1;
        poker(a1);poker(a2);
        a1=analyse(a1);a2=analyse(a2);
        b1=Analyse(b1);b2=Analyse(b2);
        player=count(a1,a2);computer=count(b1,b2);
        Decide(player,computer);
    }
}
void poker(int x)
{
    void heart(int x);void club(int x);
    void spade(int x);void diamond(int x);
    if(x>=1&&x<=13)
        heart(x);
    else if(x>=14&&x<=26)
        club(x);
    else if(x>=27&&x<=39)
        spade(x);
    else diamond(x);
}
void heart(int x)
{char m1=201,m2=187,m3=200,m4=188,m5=205,m6=186;
char p=3;
printf("%c%c%c\n",m1,m5,m2);
printf("%d",x);
printf("%c%c%c\n",m6,p,m6);
printf("%c%c%c\n",m3,m5,m4);
}
void club(int x)
{
char m1=201,m2=187,m3=200,m4=188,m5=205,m6=186;
char p=5;
if(x%13==0)
x=13;
else x=x%13;
printf("%c%c%c\n",m1,m5,m2);
printf("%d",x);
printf("%c%c%c\n",m6,p,m6);
printf("%c%c%c\n",m3,m5,m4);
}
void spade(int x)
{
char m1=201,m2=187,m3=200,m4=188,m5=205,m6=186;
char p=6;
if(x%13==0)
x=13;
else x=x%13;
printf("%c%c%c\n",m1,m5,m2);
printf("%d",x);
printf("%c%c%c\n",m6,p,m6);
printf("%c%c%c\n",m3,m5,m4);
}
void diamond(int x)
{
char m1=201,m2=187,m3=200,m4=188,m5=205,m6=186;
char p=4;
if(x%13==0)
x=13;
else x=x%13;
printf("%c%c%c\n",m1,m5,m2);
printf("%d",x);
printf("%c%c%c\n",m6,p,m6);
printf("%c%c%c\n",m3,m5,m4);
}
int analyse(int x)
{int choose(int p),m;
    x=x%13;
    if(x==1||x==11||x==12||x==0)
        m=choose(x);
    return m;
}
int Analyse(int x)
{int choose(int p),m;
    x=x%13;
    if(x==11||x==12||x==0)
    m=10;
    return m;
}
int choose(int x)
{
    int t,p;
    if(x==1)
    {printf("You can choose 1 or 11 to decide your score\n");
    scanf("%d",&t);
    p=t;}
    else p=10;
    return p;
}
int count(int x,int y)
{
    int t;
    if(x+y>21)
        t=0;
    else t=x+y;
    return t;
}
void Decide(int player,int computer)
{
    int mark1(int player);int mark2(int computer);
    void compare(int x,int y);
    char string[10];
    printf("your score is:%d",x);
    printf("If you want another poker,enter yes,otherwise no.\n");
    gets(string);
    if(strcmp(string,"yes")==0)
    {    player=mark1(player);
    computer=mark2(computer);
    Decide(player,computer);
    }
    else compare(player,computer);
}
int mark1(int player)
{void poker(int x);
int analyse(int x);
int count(int x,int y);
    int p;
    p=rand()%52+1;
    poker(p);
    p=analyse(p);
    player=count(player,p);
    n1++;
    return player;
}
int mark2(int computer)
{
    int analyse(int x);
int count(int x,int y);
    int t;
    if(computer<=15)
    {t=rand()%52+1;
    t=analyse(t);
    computer=count(computer,t);
    n2++;}
    return computer;
}
void compare(int x,int y)
{
    if(x>y)
        printf("You are the winner!congratulations!\n");
    else if(x==y)
        printf("this is a draw");
    else printf("I am sorry to tell you that you lose the game.");
}
搜索更多相关主题的帖子: otherwise computer include playing return 
2015-01-30 01:15
somnus517
Rank: 1
等 级:新手上路
帖 子:1
专家分:7
注 册:2015-1-24
得分:7 
至少没有先声明子函数
2015-01-30 01:50
贰贰
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2015-1-9
得分:0 
回复 2楼 somnus517
子函数不是只要在调用函数中声明就好了么  主函数中也要吗
2015-01-30 09:35
砖家的谎言
Rank: 12Rank: 12Rank: 12
等 级:禁止访问
威 望:30
帖 子:693
专家分:3898
注 册:2013-12-6
得分:7 
这样可以声明,最好把函数放在最前面声明,把源文件放上来看看

我不是砖家,要努力成为砖家。
2015-01-30 11:50
韶志
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:斗气大陆
等 级:贵宾
威 望:44
帖 子:2223
专家分:13592
注 册:2013-3-22
得分:7 
好长的啊

三十年河东,三十年河西,莫欺少年穷!
2015-02-04 14:48



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-441623-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.939397 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved