| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 502 人关注过本帖
标题:【求各位大神帮助!!】EXE停止工作
只看楼主 加入收藏
affectionfla
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-12-26
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
【求各位大神帮助!!】EXE停止工作
#include <time.h>
#include<stdlib.h>
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#include<stdlib.h>
int random(int x);
int question(void);
void output(int x,char p[][30]);

int random(int x) //产生随机数的函数
{
  int r;
  srand((unsigned)time(NULL));
  r=rand()%x;
return(r);
}

int question()//生成题目的函数
{
    int a,b,c,z;
    srand((unsigned)time(NULL));
LOOP:a=rand()%50;//a在0到50内取值
    b=rand()%50;//b在0到50内取值
    c=random(2);
    if(c==0)//0到1内取整数,若等于0生成加法,等于1生成减法
    {
        z=a+b;
        if(z<0||z>50)//判断z是否在0到50之间
           goto LOOP;
        printf("%d+%d=\n",a,b);
    }
    else
    {
        z=a-b;
        if(z<0||z>50)//判断z是否在0到50之间
           goto LOOP;
        printf("%d-%d=\n",a,b);
    }
    return(z);
}

void output(int x,char p[][30])//生成评价的程序
{
    int i,j;   
    j=random(x);
    i=0;
    do
    {
        printf("%s",p[j][i]);
        i++;
    }
    while(p[j][i]=='\0');
    printf("\n");
}

int main()
{
    int i,k,score=0,result;
    char a[][30]={{"Right!"},{"Correct!"},{"You got it!"},{"The answer is right!"},{"Gaoging!"}};
    char b[][30]={{"Error! Try again, please."},{"Wrong! Once more, please."},{"No! A second time, please"}};
    char c[][30]={{"Error! Try again, please."},{"Wrong! Once more, please."},{"No! The last time, please"}};
    time_t first,second;
    srand((int)time(0));
    first=time(NULL); //计时开始
    for(i=0;i<10;i++)
    {
        result=question();//生成题目
        printf("请输入答案:\n");
        scanf("%d",&k);
        if(k=result)
        {
            score=score+10;
            output(5,a);
        }
        else
        {
            output(3,b);
            printf("请输入答案:\n");
            scanf("%d",&k);
            if(k=result)
            {
                score=score+7;
                output(5,a);
            }
            else
            {
                output(3,c);
                printf("请输入答案:\n");
                scanf("%d",&k);
                if(k=result)
                {
                    score=score+5;
                    output(5,a);
                }
                else
                {
                    printf("No, the answer is %d",result);
                }
            }
        }
    }
    second=time(NULL); //计时结束
    printf("共用时:%f seconds\n",difftime(second,first));
    printf("总分为:%d\n",score);
    getch();
    return 0;
}

刚学习C语言,好多还不熟练,捣鼓了一晚上才把错误全部解决,可是一运行每当输入完敲空格就跳出EXE停止工作,求各位大神帮助啊!~~
搜索更多相关主题的帖子: 工作 question include return 
2011-12-26 00:05
lyl59840
Rank: 2
等 级:论坛游民
帖 子:25
专家分:22
注 册:2011-12-14
收藏
得分:10 
代码问题,调代码把
2011-12-26 02:00
embed_xuel
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:58
帖 子:3845
专家分:11385
注 册:2011-9-13
收藏
得分:10 
回复 楼主 affectionfla
两个问题,
一、main函数里面用到了几次这条语句,if(k=result),这里如果是判断应该是用==。
二、output函数里面的while循环为什么要用i自增?

总有那身价贱的人给作业贴回复完整的代码
2011-12-26 05:18
快速回复:【求各位大神帮助!!】EXE停止工作
数据加载中...
 
   



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

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