| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 591 人关注过本帖
标题:由计算机生成简单的四则运算
只看楼主 加入收藏
甲鱼
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2008-10-4
收藏
 问题点数:0 回复次数:0 
由计算机生成简单的四则运算
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void plus(int key,int m,int n)
{
    if((m+n)==key)
        printf("you've done a great job");
    else printf("you are wrong");
}
void minus(int key,int m,int n)
{
    if((m-n)==key)         printf("you've done a great job");
    else printf("you are wrong");
}
void mutiply(int key,int m,int n)
{
    if((m*n)==key) printf("you've done a great job");
    else printf("you are wrong");
}
void division(float result ,int m,int n)
{
    if((m/n)==result)
        printf("you've done a great job");
    else printf("you are wrong");
}




void operate()
{    
    char ch,a[10];
    int key;
    printf("please choose the style of computation:");
    scanf("%c",&ch);
    if((ch=getchar())=='+')
    {
        int m,n;
        printf("tens digit or one digit?");
    gets(a);
    if(strcmp(a,"tens digit")==0)
    {
        m=rand()%100;n=rand()%100;
        printf("%d+%d=",m,n);
        scanf("%d",&key);
        plus(key,m,n);
    }
    else if(strcmp(a,"one digit")==0)
    {
        m=rand()%10;n=rand()%10;
        printf("%d+%d=",m,n);
        scanf("%d",&key);
        plus(key,m,n);
    }
    }
    if((ch=getchar())=='-')
    {
        int m,n;
        printf("tens digit or one digit?");
        gets(a);
        if(strcmp(a,"tens digit")==0)
        {
            m=rand()%100;n=rand()%100;
            printf("%d-%d=",m,n);
            scanf("%d",&key);
            minus(key,m,n);
        }
        else if(strcmp(a,"one digit")==0)
        {
            m=rand()%10;n=rand()%10;
            printf("%d-%d=",m,n);
            scanf("%d",&key);
            minus(key,m,n);
        }
    }
    if((ch=getchar())=='*')
    {
        int m,n;
        printf("tens digit or one digit?");
        gets(a);
        if(strcmp(a,"tens digit")==0)
        {
            m=rand()%100;n=rand()%100;
            printf("%d*%d=",m,n);
            scanf("%d",&key);
            mutiply(key,m,n);
        }
        else if(strcmp(a,"one digit")==0)
        {
            m=rand()%10;n=rand()%10;
            printf("%d*%d=",m,n);
            scanf("%d",&key);
            mutiply(key,m,n);
        }
    }
    if((ch=getchar())=='/')
    {
        int m,n;
        float result;
        printf("tens digit or one digit?");
        gets(a);
        if(strcmp(a,"tens digit")==0)
        {
            m=rand()%100;n=rand()%100;
            printf("%d/%d=",m,n);
            scanf("%f",&result);
            division(result,m,n);
        }
        else if(strcmp(a,"one digit")==0)
        {
            m=rand()%10;n=rand()%10;
            printf("%d/%d=",m,n);
            scanf("%f",&result);
            division(result,m,n);
        }
    }
}
    
void main()
{
    char t;
    do
    {
    printf("Do you want to start?");
    if((t=getchar())=='Y') operate();
    }while((t=getchar())=='N');
}
题目是由计算机生成简单的四则运算题;用户给出答案;计算机判断对错。直到用户回答说不再继续做了时结束程序
个位帮我看看到底哪出错了,拜求!!!!
搜索更多相关主题的帖子: 计算机 运算 
2008-10-24 22:53
快速回复:由计算机生成简单的四则运算
数据加载中...
 
   



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

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