| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 577 人关注过本帖
标题:c++函数问题
只看楼主 加入收藏
a7053269
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-10-22
收藏
 问题点数:0 回复次数:4 
c++函数问题
现在你要为一个小学开发一个四则运算练习的系统。用户可以选择四则运算的范围,比如10以内的四则运算等等,用户还可以输入需要做多少题,然后,程序输出题目,每输出一题,用户就要输入一个答案,最后系统给出一个成绩,比如一共出20题,用户答对了12题,那么输出"共20题,答对12题,正确率为0.6"。

我刚学c语言 ,所以各位大大们做的不要太难!
麻烦各位大大了!
搜索更多相关主题的帖子: 函数 
2008-11-03 22:41
smltq
Rank: 6Rank: 6
等 级:侠之大者
威 望:8
帖 子:566
专家分:400
注 册:2008-1-21
收藏
得分:0 
也是以前老师叫偶们做的题,不够偶是自己写的

简单的生活
2008-11-03 22:56
yuxiang8200
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2007-11-25
收藏
得分:0 
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <math.h>
void math()
{
    double dim = 0;
    int num = 0;
    int i = 0;
    int right = 0 ;//
    int wrong = 0 ;//
    time_t t;
    int choose = 0;
    int op_1 = 0 ,op_2 = 0;
    double result = 0;
    double trueresult = 0;
    srand((unsigned)time(&t));
    printf("Enter the dimension:");
    scanf("%lf" ,&dim);
    //printf("%f\n",dim);
    printf("Enter how many question you want to do:");
    scanf("%d" ,&num);
    //printf("%d\n",num);
    for(i = 0 ; i < num ; i++)
    {
        choose = rand()%4;
        switch(choose)
        {
        case 0://add
            op_1 = rand()%(num+1);
            op_2 = rand()%(num+1);
            printf("%d + %d = " , op_1 , op_2);
            scanf("%lf" , &result);
            trueresult = (double)op_1 + op_2;
            if( fabs(result-trueresult) < 0.01 )
            {
                right++;
                printf("Congratulations ,you give the right answer!\n");
            }
            else
            {
                wrong++;
                printf("Oh, it's so pity,your answer is wrong,but donot lose heart!\n");
            }
            break;
        case 1://substract
            op_1 = rand()%num;
            op_2 = rand()%num;
            if(op_1 > op_2)
            {
                printf("%d - %d = " , op_1 , op_2);
                scanf("%lf" , &result);
                trueresult =(double) op_1 - op_2;
                if( fabs(result-trueresult) < 0.01 )
                {
                    right++;
                    printf("Congratulations ,you give the right answer!\n");
                }
                else
                {
                     wrong++;
                    printf("Oh, it's so pity,your answer is wrong,but donot lose heart!\n");
                }
            }
            else
            {
                printf("%d - %d = " , op_2 , op_1);
                scanf("%lf" , &result);
                trueresult =(double)  op_2 - op_1;
                if( fabs(result-trueresult) < 0.01 )
                {
                    right++;
                    printf("Congratulations ,you give the right answer!\n");
                }
                else
                {
                     wrong++;
                    printf("Oh, it's so pity,your answer is wrong,but donot lose heart!\n");
                }
            }
            break;
        case 2://mutiply
            op_1 = rand()%num;
            op_2 = rand()%num;
            printf("%d * %d = " , op_1 , op_2);
            scanf("%lf" , &result);
            trueresult = (double) op_1 * op_2;
            if( fabs(result-trueresult) < 0.01 )
            {
                right++;
                printf("Congratulations ,you give the right answer!\n");
            }
            else
            {
                   wrong++;
                printf("Oh, it's so pity,your answer is wrong,but donot lose heart!\n");
            }
            break;
        case 3:
            op_1 = rand()%num;
            op_2 = rand()%num;
            while(op_2 == 0)
               op_2 = rand()%num;
            printf("%d / %d = " , op_1 , op_2);
            scanf("%lf" , &result);
            trueresult = (double)op_1 / op_2;
            if( fabs(result-trueresult) < 0.01 )
            {
                right++;
                printf("Congratulations ,you give the right answer!\n");
            }
            else
            {
                wrong++;
                printf("Oh, it's so pity,your answer is wrong,but donot lose heart!\n");
            }
            break;
        }
    }
    printf("Total question is:%d\n" , num);
    printf("Given right answer is:%d\n" , right);
    printf("Given worng answer is:%d\n" , wrong);
    printf("Correct answer rate is:%f\n" , (double)right/num);
}
int main()
{
    math();
    return 0;
}
仅供参考!!!呵呵
2008-11-04 13:37
风居住的街道
Rank: 1
等 级:新手上路
帖 子:374
专家分:0
注 册:2008-10-24
收藏
得分:0 
可是,为什么写“C++问题”呢?
2008-11-04 14:06
forever74
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:CC
等 级:版主
威 望:58
帖 子:1705
专家分:4345
注 册:2007-12-27
收藏
得分:0 
回复 4# 的帖子
标题党

对宇宙最严谨的描述应该就是宇宙其实是不严谨的
2008-11-04 18:57
快速回复:c++函数问题
数据加载中...
 
   



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

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