标题:小学生算数系统代码,求大神帮忙看一下,给个注释
只看楼主
LH111111
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2019-6-18
结帖率:0
已结贴  问题点数:20 回复次数:1 
小学生算数系统代码,求大神帮忙看一下,给个注释
#include<stdio.h>
#include<windows.h>
#include<time.h>
#include <stdlib.h>
void gotoxy(int x,int y);
double goadd(void);
char mygetchar(void);
int main(void)
{
    char i;
    double pa;
    printf("选择练习项目:\n");
    printf("1)练习加法  2)练习减法\n");
    printf("1)练习乘法  2)练习除法\n");
    printf("5)退出系统\n");
    while(i=mygetchar())
    {
        if(i>'0'&&i<'6')
            break;
        printf("输入错误!请重新输入:");
    }
    switch(i)
    {
    case '1' : system("cls");pa=goadd();break;
    case '2' : break;
    }
    printf("您的正确率为:%.2lf%%",pa*100);
    getchar();
    return 0;
}
double goadd(void)
{
    int a[5],b[5],i,m=0,n=0,x,y=0;
    double p;
    char ch,ch2;
    srand((unsigned)time(NULL));
    do
    {    system("cls");   
        printf("选择范围:\n");
        printf("a)0-10   b)0-20\n");
        printf("c)0-50   d)0-100\n");
        ch=mygetchar();
        while(ch<'a'||ch>'d')
        {
            printf("输入错误!请重新输入:");
            y++;
            ch=mygetchar();
        }
        if(ch=='a')
        {
            for(i=0;i<5;++i)
                {
                    a[i]=rand()%11;
                    b[i]=rand()%11;
                    printf("%2d+%2d=\n",a[i],b[i]);
                }
        }
        if(ch=='b')
        {
            for(i=0;i<5;++i)
                {
                    a[i]=rand()%21;
                    b[i]=rand()%21;
                    printf("%2d+%2d=\n",a[i],b[i]);
                }
        }
        if(ch=='c')
        {
            for(i=0;i<5;++i)
                {
                    a[i]=rand()%51;
                    b[i]=rand()%51;
                    printf("%2d+%2d=\n",a[i],b[i]);
                }
        }
        if(ch=='d')
        {
            for(i=0;i<5;++i)
                {
                    a[i]=rand()%101;
                    b[i]=rand()%101;
                    printf("%2d+%2d=\n",a[i],b[i]);
                }
        }
        for(i=0;i<5;++i)
        {
            m++;
            gotoxy(7,i+y+4);
            scanf_s("%d",&x);
            if(x==a[i]+b[i])
            {
                gotoxy(15,i+y+4);
                printf("√");
                n++;
            }
            else
            {
                gotoxy(15,i+y+4);
                printf("×");
            }
        }
        while(getchar()!='\n')
            continue;
        printf("\n是否继续?(Y/N)\n");
        ch2=mygetchar();
    }while(ch2!='N'&&ch2!='n');
    system("cls");
    p=(1.0*n)/m;
    gotoxy(26,12);
    return p;
}
void gotoxy(int x, int y)
{
    COORD coord = {x, y};   
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
char mygetchar(void)
{
    char ch;
    ch=getchar();
    while(getchar()!='\n')
        continue;   
    return ch;
}
搜索更多相关主题的帖子: void int char printf rand 
2019-06-18 17:52
吕孟伟
Rank: 8Rank: 8
等 级:贵宾
威 望:27
帖 子:200
专家分:870
注 册:2018-10-4
得分:20 
请问哪行代码看不懂?

借用一下侯捷的话:勿在浮沙筑高台。
2019-06-18 18:53



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




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

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