| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 435 人关注过本帖
标题:请帮忙看一下,这个程序错在哪儿
只看楼主 加入收藏
GF2010
Rank: 1
等 级:新手上路
帖 子:10
专家分:1
注 册:2010-4-1
结帖率:75%
收藏
已结贴  问题点数:20 回复次数:5 
请帮忙看一下,这个程序错在哪儿
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void main()
{int add(int a,int b);
 int a,b,N,c,i,p,q;
 for (i=0;i<N;i++)
a=1+rand()%50;
b=1+rand()%50;

c=add(a,b);
scanf("%d,%d",&a,&b);
printf("一共作对%d道题目\n",p);
printf("一共做错%d道题目\n",q);
}
int add(int x,int y)
{int e,g,p,q;
p=0;
q=0;
e=x+y;
printf("%d+%d=%d\n",x,y,e);
printf("请输入您的答案\n");
scanf("%d",&g);
if (e=g);
printf("回答正确\n");
p=p+1;
return  (p);
if (e!=g);
搜索更多相关主题的帖子: include 
2010-05-09 10:50
jcslt
Rank: 8Rank: 8
来 自:90-xx.com
等 级:蝙蝠侠
帖 子:251
专家分:975
注 册:2009-10-10
收藏
得分:0 
错误太多了都看的累了,直接说什么题目吧!

www.
2010-05-09 12:14
xueyuhanhai
Rank: 4
等 级:业余侠客
帖 子:90
专家分:238
注 册:2010-4-5
收藏
得分:20 
我的神啊。楼主你的代码完全就是不和逻辑啊。我帮你从写了一下:
#include<stdio.h>
#include<math.h>
#include <time.h>
#include <stdlib.h>

int p=0,q=0;//用全局变量

void main()
{  
    void add(int a,int b);//函数的声明
    int a,b,N,i;
    printf("请输入做题目的次数:");
    scanf("%d",&N);
    srand(time(NULL));//建立随机数的种子
    for(i=0;i<N;i++)
    {
        a=1+rand()%50;
        b=1+rand()%50;
        add(a,b);
    }
    printf("做错的题目数是%d",q);
    printf("\n");
    printf("做对的题目数是%d",p);
    printf("\n");
}

//判断做对与做错的题目的数目
void add(int x,int y)
{   
    int e,g;
    printf("请输入您的答案\n");
    scanf("%d",&g);
    e=x+y;
    printf("%d+%d=%d\n",x,y,e);   
    if (e==g)
    {
        printf("回答正确!\n");
        p++;
    }
    else
    {
        printf("回答错误!\n");
        q++;
    }
}
我是在VC++6.0 上运行的,可以出来结果。你的题目的意思是:随便输入一个数,与随机获取的两个随机数的和做比较吧,如果正确记下次数,错误也是。并且对输入几次也做说明吧。
2010-05-09 12:41
肟狁
Rank: 2
等 级:论坛游民
帖 子:44
专家分:33
注 册:2010-5-8
收藏
得分:0 
楼主错误太多,回去看看书吧~~~
2010-05-09 13:33
ychf890225
Rank: 4
等 级:业余侠客
帖 子:85
专家分:221
注 册:2010-4-15
收藏
得分:0 
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define SIZE 10

int add(int a,int b)
{   
    int c;
    c= a+b;
    return c;
}

main()
{
    int add1;
    int add2;
    int counter=0;
    int    a;
    int result;
    char answer;
    int score;
    int i=1;
    int wrong1[11]={0,0,0,0,0,0,0,0,0,0,0};
    int wrong2[11]={0,0,0,0,0,0,0,0,0,0,0};
    int wrong[11]={0,0,0,0,0,0,0,0,0,0,0};

    printf("\tA math test for the year one schoolchildren\n\n");
   
    for(i;i<=SIZE;i++)
        {
            srand(time(NULL));
            add1=rand()%20+1;
            add2=rand()%20+1;
        
            printf("\(%d\)\t\t\t%d+%d=",i,add1,add2);
            scanf("%d",&a);
   
            result=add(add1,add2);

            if(a==result)
            {
                printf("You're right!\n");
                counter++;
            }
            else
            {
                printf("You are wrong!Be careful!\n");
                wrong1[i]=add1;
                wrong2[i]=add2;
                wrong[i]=result;
            }

        }

        printf("\n\n\n");

        for(i=1;i<=SIZE;i++)
        {
            if(wrong1[i]!=0)
            {
                printf("the set of the wrongs:");
                printf("\(%d\)\t\t\t%d+%d=%d\n",i,wrong1[i],wrong2[i],wrong[i]);
            }
            else
                ;
        }

        printf("\n\n");
        score=counter*10;
        printf("The mark you got is %d\n\n",score);
}
2010-05-09 14:31
南国利剑
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:29
帖 子:1165
专家分:3536
注 册:2010-4-12
收藏
得分:0 
提问的话要给出代码的注释,和这个代码要实现的功能。

南国利剑
2010-05-09 15:01
快速回复:请帮忙看一下,这个程序错在哪儿
数据加载中...
 
   



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

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