| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 576 人关注过本帖, 1 人收藏
标题:小学生四则运算系统。。出错了。。不知道这么改。。
只看楼主 加入收藏
zyxandycx
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2012-5-31
结帖率:66.67%
收藏(1)
已结贴  问题点数:20 回复次数:5 
小学生四则运算系统。。出错了。。不知道这么改。。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#define header1 小学生四则运算系统

int saveflag=1;
int flag=0;
int k;

struct student{
    char ID[20];
    char name[20];
    int month;
    int year;
    int score;
} stu[1000];

struct student1{
    char ID[20];
    char name[20];
    int month;
    int year;
    int score;
} stuexchange[1000];



void whetherregister()
{
    printf("如果还没注册,请注册用户-1,如果已经注册,请输入用户名-2,退出-0\n");
}

void register_ID()
{
      printf("请输入用户名(16个字符以内):");
      scanf("%s",stu[saveflag].ID);
       //if(savecheck(stu[saveflag].ID,saveflag)==1)
         //register_ID();
      //else
        printf("用户名注册成功.\n");
   
}

void inputmoreinformation()
{
    printf("请输入您的姓名:");
    scanf("%s",stu[saveflag].name);
    printf("请输入您的出生年份:");
    scanf("%d",&stu[saveflag].year);
    printf("请输入您的出生月份:");
    scanf("%d",&stu[saveflag].month);
}

void login(char name)
{
     printf("请输入您的用户名:");
      scanf("%s",name);
      if(inputcheck(name,saveflag)!=2)
        printf("账号输入有误!\n");
      else
        login(name);
      
}

void save(int k)
{
    FILE *fp;
    int i;
    if((fp=fopen("D:\\list","wb"))==NULL)
    {printf("\n文件打开出错!\n");
    getchar();
    return;}
    for(i=0;i<k;i++)
     if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
       printf("文件读取出错!\n");
     fclose(fp);
}

void savecheck(char ID,int k)
{
    FILE *fp;
    int i;
    fp=fopen("D:\\list","rb");
    for(i=0;i<k;i++)
      {fread(&stu[i],sizeof(struct student),1,fp);
      if(strcmp(ID,stu[i].ID)==0)
        {
            printf("该用户名已经被注册,请重新输入\n");
            flag=1;
        }
      }
    fclose(fp);
    return flag;
}

void inputcheck(char ID,int k)
{
    FILE *fp;
    int i;
    fp=fopen("D:\\list","rb");
    for(i=0;i<k;i++)
    {
        fread(&stu[i],sizeof(struct student),1,fp);
        if(strcmp(ID,stu[i].ID)==0)
          {
             printf("登陆成功!\n");
             flag=2;
          }
    }
    return flag;
}

void ranking_list(int k)
{
     FILE *fp = fopen("D:\\list","rb");
     int i=0,j=0;
   while(!feof(fp))
   {
        fscanf(fp,"%d",&stu[i].score);
        i++;
   }
   printf("排行榜\n");
   for(i=0;i<k-1;i++)
     for(j=i;j<k;j++)
     if(stu[i].score<stu[j].score)
        {
         //  stuexchange[j]=stu[j];
          // stu[j]=stu[i];
           //stu[i]=stuexchange[j];
        }
     for(i=0;i<k;i++)
        printf("%s %d %d %d",stu[i].name,stu[i].year,stu[i].month,stu[i].score);
   printf("\n");
}

int p1()
{
    time_t t;
    int h,i,g,j,a[100],b[100];
    srand((unsigned)time(&t));
    for(i=0;i<10;i++)
    {
        a[i]=rand()%9+1;
        for(j=0;;j++)
        {
            b[i]=rand()%9+1;
            if(k==1)
                {
                    printf("%d+%d=",a[i],b[i]);
                    scanf("%d",&h);
                    if(h==a[i]+b[i])
                    {
                    printf("答对了,你真棒!\n");
                    stu[saveflag].score+=10;
                    break;
                    }
                    else
                    {
                        printf("答错了,不要灰心哦!\n");
                        break;
                    }   
            
                }
                else if(k==2)
                {
                    if(a[i]<b[i])
                    {
                        g=a[i];
                        a[i]=b[i];
                        b[i]=g;
                    }
                    printf("%d-%d=",a[i],b[i]);
                    scanf("%d",&h);
                    if(h==a[i]-b[i])
                    {
                    printf("答对了,你真棒!\n");
                    stu[saveflag].score+=10;
                    break;
                    }
                    else
                    {
                        printf("答错了,不要灰心哦!\n");
                        break;
                    }   
            
                }
                else if(k==3)
                {
                    printf("%d*%d=",a[i],b[i]);
                    scanf("%d",&h);
                    if(h==a[i]*b[i])
                    {
                    printf("答对了,你真棒!\n");
                    stu[saveflag].score+=10;
                    break;
                    }
                    else
                    {
                        printf("答错了,不要灰心哦!\n");
                        break;
                    }   
                }
                else if(k==4)
                {
                    float s;
                    printf("%d/%d=",a[i],b[i]);
                    scanf("%f",&s);
                    if(s==(float)a[i]/b[i])
                    {
                    printf("答对了,你真棒!\n");
                    stu[saveflag].score+=10;
                    break;
                    }
                    else
                    {
                        printf("答错了,不要灰心哦!\n");
                        break;
                }
            }
        }
    }
    printf("你的最后得分为:%d\n",stu[saveflag].score);
}


int p2()
{
    time_t t;
    int h,g,i,j,a[100],b[100];
    srand((unsigned)time(&t));
    for(i=0;i<10;i++)
    {
        a[i]=rand()%90+10;
        for(j=0;;j++)
        {
            b[i]=rand()%90+10;
            if(k==1)
            {
                printf("%d+%d=",a[i],b[i]);
                scanf("%d",&h);
                if(h==a[i]+b[i])
                {
                    printf("答对了,你真棒!\n");
                    stu[saveflag].score+=10;
                    break;
                }
                else
                {
                    printf("答错了,不要灰心哦!\n");
                    break;
                }   
            }
            else if(k==2)
            {
                if(a[i]<b[i])
                    {
                        g=a[i];
                        a[i]=b[i];
                        b[i]=g;
                    }
                printf("%d-%d=",a[i],b[i]);
                scanf("%d",&h);
                if(h==a[i]-b[i])
                {
                    printf("答对了,你真棒!\n");
                    stu[saveflag].score+=10;
                    break;
                }
                else
                {
                    printf("答错了,不要灰心哦!\n");
                    break;
                }   
            }
            else if(k==3)
            {
                printf("%d*%d=",a[i],b[i]);
                scanf("%d",&h);
                if(h==a[i]*b[i])
                {
                    printf("答对了,你真棒!\n");
                    stu[saveflag].score+=10;
                    break;
                }
                else
                {
                    printf("答错了,不要灰心哦!\n");
                    break;
                }   
            }
            else if(k==4)
            {
                printf("%d/%d=",a[i],b[i]);
                scanf("%d",&h);
                if(h==a[i]/b[i])
                {
                    printf("答对了,你真棒!\n");
                    stu[saveflag].score+=10;
                    break;
                }
                else
                {
                    printf("答错了,不要灰心哦!\n");
                    break;
                }   
            }
        }
    }
        printf("你的最后得分为:%d\n",stu[saveflag].score);
}


int p3()
{
    time_t t;
    int i,x,y,j;
    float h,e,a[100],b[100];

    srand((unsigned)time(&t));
    for(i=0;i<10;i++)
    {
    a[i]=rand()%1000;
    a[i]=a[i]/100.00;
        for(j=0;;j++)
        {
            b[i]=rand()%900+100;
            b[i]=b[i]/100.00;
                printf("%.2f+%.2f=",a[i],b[i]);
                    e=a[i]+b[i];
                printf("%f\n",a[i]+b[i]);
                    scanf("%f",&h);
                if(h==e)
                {
                    printf("答对了,你真棒!\n");
                    stu[saveflag].score+=10;
                    break;
                }
                else
                {
                    printf("答错了,不要灰心哦!\n");
                    break;
                }   
            
        }
    }
        printf("你的最后得分为:%d\n",stu[saveflag].score);
}



int main()
{
    int i,h;
    int a;
    char name[20];
        printf("小学生四则运算系统\n") ;
        whetherregister();
        scanf("%d",&h);
        
        if(h==1)
        {
           register_ID();
           inputmoreinformation();
           save(saveflag);
           saveflag++;
        }
        if(h==2)
          login(name);
        
        printf("请选择运算类型:1:+ 2:- 3:* 4:/ \n");
            scanf("%d",&k);
            

   
    printf("请选择难度系数:1:第一级 10以内的运算 2:第二级 100以内的运算 3:第三级 小数运算\n");
    scanf("%d",&a);
    switch(a)
    {
        case 1:p1();break;
        case 2:p2();break;
        case 3:p3();break;
    }
    printf("成绩排行榜-1,退出-2:");
    scanf("%d",i);
    switch(i)
    {
      // case 1 : rangking_list(saveflag);break;
       case 2 : whetherregister();break;
    }
}


要求:
(1)    学生进行系统时,要求输入他的帐号,若没有帐号,则让其注册,注册时,要输出姓名,出生年月(要用文件保存)
(2)    学生在答题前能够选择是进行什么运算的练习,运算包括:+、-、*、/
(3)    每种运算设立三级难度系数,第一级为10以内的运算,第二级为100以内的运算,第三级为小数运算。学生答题前能够选择难度系数。
(4)    每次答题数量为10个问题,每题10分,根据答对题的多少给出对学生的评价(自己设计评语)
(5)    学生答题完毕后给出答题排行榜。(要用文件保存)
求各位大神帮帮忙!!!!!!


[ 本帖最后由 zyxandycx 于 2012-5-31 16:49 编辑 ]
搜索更多相关主题的帖子: 注册 小学生 include 用户名 
2012-05-31 15:45
rjvsky
Rank: 3Rank: 3
来 自:陕西西安
等 级:论坛游侠
帖 子:77
专家分:106
注 册:2012-3-6
收藏
得分:7 
好长啊!!

企业需要的人才,是真正可以给他们带来经济效益的人,而不是一大堆没用的证书,看淡证书,强化自己···
2012-06-01 17:42
zyxandycx
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2012-5-31
收藏
得分:0 
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "time.h"

int  saveflag=0;
int  flag=0;
int  k;
int  a;

void menu1();
void menu2();
void regi();
void login();
void regi_check();
void log_check();
void save();
void choice2();
void choice();
void inputmore();
void sort();
void ranking_list();
int p1();
int p2();
int p3();

 struct student{
    char ID[20];
    char name[20];
     int month;
     int year;
      int score;
 }           ;

struct student stu[1000];

void menu1()
{
    int c;

    printf("如果还没注册,请按 1 注册用户\n如果已经注册,请按 2 输入用户名\n退出请按0\n");
    scanf("%d",&c);
    switch(c)
    {
        case 1 : regi();
          break;
        case 2 : login();
          break;
        case 0 : printf("谢谢您的使用,我们会继续努力,为您设计更好的系统^_^\n");
            break;
    }
}

void regi()
{
      printf("请输入用户名注册(16个字符以内):");
        scanf("%s",stu[saveflag].ID);
        regi_check(stu[saveflag].ID);
           if((flag==1) && (saveflag !=0))
             {
               printf("用户名已经存在,请重新输入.\n");
               regi();
             }
        else
          {
            printf("用户名注册成功.\n");
            inputmore();

            choice2();
            saveflag++;
          }
}

void choice2()
{
    int select;
    printf("按 1 开始测试;     按 2 返回主界面\n");
    scanf("%d",select);
    switch(select)
    {
        case 1 : choice();

        case 2 : menu1();
            break;
    }
}

void inputmore()
{
    printf("请输入您的姓名:");
    scanf("%s",stu[saveflag].name);
    printf("请输入您的出生年份:");
    scanf("%d",&stu[saveflag].year);
    printf("请输入您的出生月份:");
    scanf("%d",&stu[saveflag].month);
}

void login()
{
    char name1;
     printf("请输入您的用户名:");
      scanf("%s",name1);
      log_check(name1);
      if(flag==2)
       {
         printf("账号输入有误!\n");
           login();
       }
      else
      {
        printf("登陆成功!\n");
       choice();
       menu2();
      }
}

void choice()
{
    printf("请选择运算类型:1:+ 2:- 3:* 4:/ \n");

      scanf("%d",&k);
            
    printf("请选择难度系数:1:第一级 10以内的运算 2:第二级 100以内的运算 3:第三级 小数运算\n");
        scanf("%d",&a);
    switch(a)
    {
        case 1:p1();
            break;
        case 2:p2();
            break;
        case 3:p3();
            break;
    }
}


void menu2()
{
    int ag;
    printf("再来一次请按 1 \n查询成绩请按 2 \n退出请按 0\n");
    scanf("%d",&ag);
    switch(ag)
    {
        case 1 : choice();
           break;
        case 2 : ranking_list();
          break;
        case 0: printf("谢谢您的使用,我们会继续努力,为您设计更好的系统^_^\n");
            break;
    }
}

void save()
{
    FILE *fp;
    int i;
    if((fp=fopen("D:\\list","wb"))==NULL)
     {printf("\n文件打开出错!\n");
        getchar();
        return;}
    for(i=0;i<saveflag;i++)
     if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
       printf("文件读取出错!\n");
     fclose(fp);
}

void regi_check(char *name1)
{
    FILE *fp;
    int i;
    fp=fopen("D:\\list","rb");
    for(i=0;i<saveflag;i++)
      {fread(&stu[i],sizeof(struct student),1,fp);
        if(strcmp(name1,stu[i].ID)==0)
          flag=1;
      }
    fclose(fp);
}

void log_check(char *name1)
{
    FILE *fp;
    int i;
    fp=fopen("D:\\list","rb");
    for(i=0;i<saveflag;i++)
    {
        fread(&stu[i],sizeof(struct student),1,fp);
        if(strcmp(name1,stu[i].ID)==0)
             flag=2;
    }
    fclose(fp);
}

void sort(struct student *ptr,int n)
{
    int i,j;
    struct student t;
    for(i=1;i<n;i++)
        for(j=0;j<n-i;j++)
            if((*(ptr+j)).score < (*(ptr+j+1)).score)
            {
                t=*(ptr+j);
                *(ptr+j)=*(ptr+j+1);
                *(ptr+j+1)=t;
            }
}

void ranking_list()
{
     FILE *fp = fopen("D:\\list","rb");
     int i=0;
     struct student stu[1000],*ptr;
     ptr=stu;
   while(!feof(fp))
   {
        fscanf(fp,"%d",&stu[i].score);
        i++;
   }
    printf("排行榜\n");
        sort(ptr,saveflag);
     for(i=0;i<saveflag;i++)
        printf("%s %d-%d %d",stu[i].name,stu[i].year,stu[i].month,stu[i].score);
   printf("\n");
  return ;
}

int p1()
{
    time_t t;
    int h,i,g,j,a[100],b[100];

        srand((unsigned)time(&t));
    for(i=0;i<10;i++)
    {
      a[i]=rand()%9+1;
        for(j=0;;j++)
        {
          b[i]=rand()%9+1;
            if(k==1)
                {
                    printf("%d+%d=",a[i],b[i]);
                        scanf("%d",&h);
                  if(h==a[i]+b[i])
                    {
                       printf("答对了,你真棒!\n");
                           stu[saveflag].score+=10;
                       break;
                    }
                else
                    {
                      printf("答错了,不要灰心哦!\n");
                        break;
                    }   
                }
            else if(k==2)
                {
                    if(a[i]<b[i])
                       {g=a[i];
                         a[i]=b[i];
                          b[i]=g;}
                    printf("%d-%d=",a[i],b[i]);
                       scanf("%d",&h);
                    if(h==a[i]-b[i])
                    {
                        printf("答对了,你真棒!\n");
                           stu[saveflag].score+=10;
                       break;
                    }
                    else
                    {
                        printf("答错了,不要灰心哦!\n");
                          break;
                    }   
                }
            else if(k==3)
                {
                  printf("%d*%d=",a[i],b[i]);
                    scanf("%d",&h);
                    if(h==a[i]*b[i])
                    {
                       printf("答对了,你真棒!\n");
                           stu[saveflag].score+=10;
                       break;
                    }
                    else
                    {
                        printf("答错了,不要灰心哦!\n");
                          break;
                    }   
                }
            else if(k==4)
                {
                    float s;
                    printf("%d/%d=",a[i],b[i]);
                       scanf("%f",&s);
                    if(s==(float)a[i]/b[i])
                    {
                       printf("答对了,你真棒!\n");
                           stu[saveflag].score+=10;
                         break;
                    }
                    else
                    {
                        printf("答错了,不要灰心哦!\n");
                               break;
                }
            }
        }
    }
    printf("你的最后得分为:%d\n",stu[saveflag].score);
}


int p2()
{
    time_t t;
   
    int h,g,i,j,a[100],b[100];
       srand((unsigned)time(&t));
    for(i=0;i<10;i++)
    {
        a[i]=rand()%90+10;
        for(j=0;;j++)
        {
                  b[i]=rand()%90+10;
        if(k==1)
            {
                printf("%d+%d=",a[i],b[i]);
                       scanf("%d",&h);
                if(h==a[i]+b[i])
                {
                    printf("答对了,你真棒!\n");
                       stu[saveflag].score+=10;
                    break;
                }
                else
                {
                    printf("答错了,不要灰心哦!\n");
                       break;
                }      
            }
        else if(k==2)
            {
                if(a[i]<b[i])
                    {
                        g=a[i];
                        a[i]=b[i];
                        b[i]=g;
                    }
                printf("%d-%d=",a[i],b[i]);
                    scanf("%d",&h);
                if(h==a[i]-b[i])
                {
                    printf("答对了,你真棒!\n");
                       stu[saveflag].score+=10;
                    break;
                }
                else
                {
                    printf("答错了,不要灰心哦!\n");
                        break;
                }   
            }
        else if(k==3)
            {
            printf("%d*%d=",a[i],b[i]);
                    scanf("%d",&h);
                if(h==a[i]*b[i])
                {
                    printf("答对了,你真棒!\n");
                       stu[saveflag].score+=10;
                    break;
                }
                else
                {
                    printf("答错了,不要灰心哦!\n");
                        break;
                }   
            }
        else if(k==4)
            {
                printf("%d/%d=",a[i],b[i]);
                scanf("%d",&h);
                if(h==a[i]/b[i])
                {
                    printf("答对了,你真棒!\n");
                       stu[saveflag].score+=10;
                    break;
                }
                else
                {
                    printf("答错了,不要灰心哦!\n");
                    break;
                }   
            }
        }
    }
        printf("你的最后得分为:%d\n",stu[saveflag].score);
}


int p3()
{
    time_t t;

    int i,x,y,j;
    float h,e,g,a,b;

       srand((unsigned)time(&t));
    for(i=0;i<10;i++)
    {
      a=rand()%1000;
      a=a/100.00;
        for(j=0;;j++)
        {
            b=rand()%900+100;
            b=b/100.00;
        if(k==1)
            {
                printf("%.2f+%.2f=",a,b);
                    e=a+b;
                    scanf("%f",&h);
                if(h==e)
                {
                    printf("答对了,你真棒!\n");
                       stu[saveflag].score+=10;
                    break;
                }
                else
                {
                    printf("答错了,不要灰心哦!\n");
                    break;
                }
            }
        else if(k==2)
           {
             if(a<b)
                    {
                        g=a;
                        a=b;
                        b=g;
                    }

                printf("%.2f-%.2f=",a,b);
                    e=a-b;
                    scanf("%f",&h);
                if(h==e)
                {
                    printf("答对了,你真棒!\n");
                       stu[saveflag].score+=10;
                    break;
                }
                else
                {
                    printf("答错了,不要灰心哦!\n");
                    break;
                }
           }
        else if(k==3)
           {
              printf("%.2f*%.2f=",a,b);
                    e=a*b;
                       scanf("%f",&h);
                if(h==e)
                {
                    printf("答对了,你真棒!\n");
                       stu[saveflag].score+=10;
                    break;
                }
                else
                {
                    printf("答错了,不要灰心哦!\n");
                    break;
                }
           }
        else if(k==4)
           {
              printf("%.2f/%.2f=",a,b);
                    e=a/b;
                    scanf("%f",&h);
                if(h==e)
                {
                    printf("答对了,你真棒!\n");
                       stu[saveflag].score+=10;
                    break;
                }
                else
                {
                    printf("答错了,不要灰心哦!\n");
                    break;
                }
           }                     
            
        }
    }
        printf("你的最后得分为:%d\n",stu[saveflag].score);
}


int main()
{
     printf("欢迎来到小学生四则运算系统\n");
          menu1();
          save();
    return 0;
}


自己改进了一下,可是还是不对。。。求高手  求大神   各种求………………
2012-06-01 20:03
heifeng2012
Rank: 3Rank: 3
来 自:上海
等 级:论坛游侠
帖 子:53
专家分:113
注 册:2012-3-22
收藏
得分:7 
太长了,
2012-06-01 20:59
li413020343
Rank: 1
等 级:新手上路
帖 子:1
专家分:7
注 册:2012-6-4
收藏
得分:7 
2222


[此贴子已经被作者于2019-1-17 10:39编辑过]

2012-06-04 13:27
zyxandycx
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2012-5-31
收藏
得分:0 
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "time.h"

int k;
int saveflag=0;
int quitflag=0;

void menu1();
void menu2();
void menu3();
void menu4();
void choice();
void stringinput(t,lens,notice) ;
void inputmore();
void regi();
void login();
void save();
void sort(ptr, n);
void ranking_list();
int p1();
int p2();
int p3();
int praise();

struct student{
    char ID[20];
    char name[20];
     int month;
     int year;
      int score;
   }   ;
   
struct student stu[1000];

void menu1()
{
    int select;
    printf("请按 1 注册用户\t\t请按 2 登陆\t按 0 退出\n");
    scanf("%d",&select);
        if(select==1)
            regi();
        if(select==2)
            login();
        if(select==0)
         quitflag=1;return;
}

void menu2()
{
    int c;
    printf("请按 1 开始答题\t退出请按 0 \n");
    scanf("%d",&c);
    switch(c)
    {
        case 1 : choice();  menu3();    break;
        case 0 : quitflag=1;break;
    }
}

void menu3()
{
    int c;
    printf("按 1 再来一次\t按 2 查看排名\t按 3 储存数据(储存数据后方可查看排名!)\n按 0 退出\n");
    scanf("%d",&c);
    switch(c)
    {
        case 1 : choice(); menu3();     break;
        case 2 : ranking_list();  break;
        case 3 : save();menu3();break;
        case 0 : quitflag=1;break;
    }
}
void menu4()
{
    int c;
    printf("1 开始答题\t2 查看排名\t3 储存数据\t0 退出\n");
    scanf("%d",&c);
    switch(c)
    {
        case 1 : choice();menu3();break;
        case 2 : ranking_list();    break;
        case 3 : save();menu3(); break;
        case 0 : quitflag=1;break;
    }
}

void choice()
{
    int a;
    printf("请选择运算类型:1:+ 2:- 3:* 4:/ \n");

      scanf("%d",&k);
            
    printf("请选择难度系数:1:第一级 10以内的运算 2:第二级 100以内的运算 3:第三级 小数运算\n");
        scanf("%d",&a);
    switch(a)
    {
        case 1:p1(); saveflag++;
            break;
        case 2:p2(); saveflag++;
            break;
        case 3:p3();  saveflag++;
            break;
    }
}

void stringinput(char *t, int lens, char *notice)
{
    char n[255];
    do{
        printf(notice);
        scanf("%s", n);
        if (strlen(n) > lens)printf("\n 输入的用户名过长!再次输入. \n");
    }while (strlen(n) > lens);
    strcpy(t, n);
}

void inputmore()
{
    printf("请输入您的姓名:");
    scanf("%s",stu[saveflag].name);
    printf("请输入您的出生年份:");
    scanf("%d",&stu[saveflag].year);
    printf("请输入您的出生月份:");
    scanf("%d",&stu[saveflag].month);
}

void regi()
{
    char num[20];
    int flag, i;
    char ch;
      stringinput(num, 20, "请输入用户名(20个字符以内):");
         flag = 0;
        for(i=0; i<saveflag; i++)      //检验是否已经存在用户名 ,存在flag==1
        {
            if (strcmp(stu[i].ID,num) == 0)
            {
                flag = 1;
                break;
            }
        }
        
       if (flag == 1)

            {  getchar();
                printf("%s 该用户名已经存在,需要再次尝试输入吗?(y/n)", num);
                scanf("%c", &ch);
                if (ch == 'y' || ch == 'Y')
                    regi();
                else
                    menu1();
            }
       else
            {
                printf("注册成功!请输入更多你的信息.\n");
                strcpy(stu[saveflag].ID, num);
                inputmore();
                menu2();
            }
}

void login()
{
    int i,flag=0,nflag;
    char num[20];
    char ch;
    printf("请输入您的用户名:");
    scanf("%s",num);
     for(i=0; i<saveflag; i++)      //检验是否已经存在用户名 ,存在flag==1
        {
            if (strcmp(stu[i].ID,num) == 0)
            {
                flag = 1;
                break;
            }
        }
        
     if (flag == 1)
     {
        printf("登陆成功!\n");
        menu4();
     }
     else
     {
        printf("%s 该用户名不存在!需要重新输入吗?(y/n):",num);
        scanf("%s", &ch);
                if (ch == 'y' || ch == 'Y')
                    login();
                else
                    menu1();
     }
}

void save()
{
    FILE *fp;
    int i;
    if((fp=fopen("D:\\list","wb"))==NULL)
     {
        printf("\n文件打开出错!\n");
            getchar();
                return;
     }
      for (i = 0;i < saveflag;i++)
      {
        fwrite(&stu[i],sizeof(struct student),1,fp);
      }
     fclose(fp);
}

void sort(struct student *ptr,int n)
{
    int i,j;
    struct student t;
    for(i=1;i<n;i++)
        for(j=0;j<n-i;j++)
            if((*(ptr+j)).score < (*(ptr+j+1)).score)
            {
                t=*(ptr+j);
                *(ptr+j)=*(ptr+j+1);
                *(ptr+j+1)=t;
            }
}

void ranking_list()
{
     FILE *fp = fopen("D:\\list","rb");
     int i=0,x=0;
     struct student stu[1000],*ptr;
     ptr=stu;
   while(!feof(fp))
   {
        fread(&stu[i],sizeof(struct student),1,fp);
        i++;
   }
   x=i;
    printf("排行榜\n");
        sort(ptr,saveflag);
     for(i=0;i<x;i++)
        printf("%s %d-%d %d\n",stu[i].name,stu[i].year,stu[i].month,stu[i].score);
   printf("\n");
  menu3();
}

int p1()
{
    time_t t;
    int h,i,g,j,a[100],b[100];

        srand((unsigned)time(&t));
    for(i=0;i<10;i++)
    {
      a[i]=rand()%9+1;
        for(j=0;;j++)
        {
          b[i]=rand()%9+1;
            if(k==1)
                {
                    printf("%d+%d=",a[i],b[i]);
                        scanf("%d",&h);
                  if(h==a[i]+b[i])
                    {
                       printf("答对了,你真棒!\n");
                           stu[saveflag].score+=10;
                       break;
                    }
                else
                    {
                      printf("答错了,不要灰心哦!\n");
                        break;
                    }   
                }
            else if(k==2)
                {
                    if(a[i]<b[i])
                       {g=a[i];
                         a[i]=b[i];
                          b[i]=g;}
                       printf("%d-%d=",a[i],b[i]);
                           scanf("%d",&h);
                       if(h==a[i]-b[i])
                       {
                           printf("答对了,你真棒!\n");
                               stu[saveflag].score+=10;
                           break;
                       }
                       else
                       {
                          printf("答错了,不要灰心哦!\n");
                             break;
                       }   
                }
            else if(k==3)
                {
                  printf("%d*%d=",a[i],b[i]);
                    scanf("%d",&h);
                    if(h==a[i]*b[i])
                    {
                       printf("答对了,你真棒!\n");
                           stu[saveflag].score+=10;
                       break;
                    }
                    else
                    {
                        printf("答错了,不要灰心哦!\n");
                          break;
                    }   
                }
            else if(k==4)
                {
                    float s;
                    printf("%d/%d=",a[i],b[i]);
                       scanf("%f",&s);
                    if(s==(float)a[i]/b[i])
                    {
                       printf("答对了,你真棒!\n");
                           stu[saveflag].score+=10;
                         break;
                    }
                    else
                    {
                        printf("答错了,不要灰心哦!\n");
                               break;
                }
            }
        }
    }
    printf("你的最后得分为:%d\n",stu[saveflag].score);
    praise();
}


int p2()
{
    time_t t;
   
    int h,g,i,j,a[100],b[100];
       srand((unsigned)time(&t));
    for(i=0;i<10;i++)
    {
        a[i]=rand()%90+10;
        for(j=0;;j++)
        {
                  b[i]=rand()%90+10;
        if(k==1)
            {
                printf("%d+%d=",a[i],b[i]);
                       scanf("%d",&h);
                if(h==a[i]+b[i])
                {
                    printf("答对了,你真棒!\n");
                       stu[saveflag].score+=10;
                    break;
                }
                else
                {
                    printf("答错了,不要灰心哦!\n");
                       break;
                }      
            }
        else if(k==2)
            {
                if(a[i]<b[i])
                    {
                        g=a[i];
                        a[i]=b[i];
                        b[i]=g;
                    }
                printf("%d-%d=",a[i],b[i]);
                    scanf("%d",&h);
                if(h==a[i]-b[i])
                {
                    printf("答对了,你真棒!\n");
                       stu[saveflag].score+=10;
                    break;
                }
                else
                {
                    printf("答错了,不要灰心哦!\n");
                        break;
                }   
            }
        else if(k==3)
            {
            printf("%d*%d=",a[i],b[i]);
                    scanf("%d",&h);
                if(h==a[i]*b[i])
                {
                    printf("答对了,你真棒!\n");
                       stu[saveflag].score+=10;
                    break;
                }
                else
                {
                    printf("答错了,不要灰心哦!\n");
                        break;
                }   
            }
        else if(k==4)
            {
                printf("%d/%d=",a[i],b[i]);
                scanf("%d",&h);
                if(h==a[i]/b[i])
                {
                    printf("答对了,你真棒!\n");
                       stu[saveflag].score+=10;
                    break;
                }
                else
                {
                    printf("答错了,不要灰心哦!\n");
                    break;
                }   
            }
        }
    }
        printf("你的最后得分为:%d\n",stu[saveflag].score);
        praise();
}


int p3()
{
    time_t t;

    int i,x,y,j;
    float h,e,g,a,b;

       srand((unsigned)time(&t));
    for(i=0;i<10;i++)
    {
      a=rand()%1000;
      a=a/100.00;
        for(j=0;;j++)
        {
            b=rand()%900+100;
            b=b/100.00;
        if(k==1)
            {
                printf("%.2f+%.2f=",a,b);
                    e=a+b;
                    scanf("%f",&h);
                if(h==e)
                {
                    printf("答对了,你真棒!\n");
                       stu[saveflag].score+=10;
                    break;
                }
                else
                {
                    printf("答错了,不要灰心哦!\n");
                    break;
                }
            }
        else if(k==2)
           {
             if(a<b)
                    {
                        g=a;
                        a=b;
                        b=g;
                    }

                printf("%.2f-%.2f=",a,b);
                    e=a-b;
                    scanf("%f",&h);
                if(h==e)
                {
                    printf("答对了,你真棒!\n");
                       stu[saveflag].score+=10;
                    break;
                }
                else
                {
                    printf("答错了,不要灰心哦!\n");
                    break;
                }
           }
        else if(k==3)
           {
              printf("%.2f*%.2f=",a,b);
                    e=a*b;
                       scanf("%f",&h);
                if(h==e)
                {
                    printf("答对了,你真棒!\n");
                       stu[saveflag].score+=10;
                    break;
                }
                else
                {
                    printf("答错了,不要灰心哦!\n");
                    break;
                }
           }
        else if(k==4)
           {
              printf("%.2f/%.2f=",a,b);
                    e=a/b;
                    scanf("%f",&h);
                if(h==e)
                {
                    printf("答对了,你真棒!\n");
                       stu[saveflag].score+=10;
                    break;
                }
                else
                {
                    printf("答错了,不要灰心哦!\n");
                    break;
                }
           }                     
            
        }
    }
        printf("你的最后得分为:%d\n",stu[saveflag].score);
        praise();
}

 int praise()
{
    if(stu[saveflag].score<50)
    {
       printf("这次做的不好,要加油了哦!\n\n\n");
    }
    else if(stu[saveflag].score<80)
    {
        printf("做的不错哦,继续加油!\n\n\n");
    }
    else if(stu[saveflag].score<100)
    {
        printf("很不错了,争取满分吧!\n\n\n");
    }
   else
     printf("非常棒!非常非常非常非常棒!你得了满分!!继续努力!!\n\n\n");
}

int main()
{
    FILE *fp;
    fp = fopen("D:\\list", "ab+"); /*以追加方式打开一个二进制文件,可读可写,若此文件不存在,会创建此文件*/
    if (fp == NULL)
    {
        printf("\n=====>can not open file!\n");
        exit(0);
    }

    while (!feof(fp))
    {
        if (fread(&stu[saveflag], sizeof(struct student), 1, fp) == 1) /*一次从文件中读取一条学生成绩记录*/
            saveflag++;
    }

    fclose(fp);
        printf("小学生四则运算系统\n");
    while(1)
    {
        menu1();
        if(quitflag==1)
            break;
    }

}

自己重新做了修改,这次解决啦!!~~~
2012-06-06 16:01
快速回复:小学生四则运算系统。。出错了。。不知道这么改。。
数据加载中...
 
   



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

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