个人项目3

Posted wmq123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了个人项目3相关的知识,希望对你有一定的参考价值。

个人项目3:可以在之前基础上实现在线答题;

答题结束后可以判断对错;

可以将错题保存起来;

设计思路:利用while语句实现选择不同种类的答题项目;同样利用while实现对错的判断。

 

 #include <stdlib.h>

#include <stdio.h>

#include <time.h>

int question_get();

int type;

void main( void )

{

   int answer,n;

   srand( (unsigned)time( NULL ) );

 

     loop:  printf( "请选择要进行测试的题目种类:" );

 

            printf( "\n1.加法运算\n2.减法运算\n3.乘法运算\n4.除法运算\n5.退出运算\n" );

 

            printf("\t\t\t请选择(1-5):");

 

            scanf( "%d", &type );

  

   while( 1 )

      {   

         int temp;

         int flag;

         answer = question_get();

         printf( "请回答:\n" );

         scanf( "%d", &temp );

         while( temp!=answer )

            {

            printf( "\n答案错误,重做\n" );

              scanf( "%d", &temp );

             }

         printf( "\n答案正确,很好\n" );

 

             printf( "继续请按1,退出请按0\n" );

           scanf( "%d", &flag );

 

         while( flag!=0&&flag!=1 )

 

   {

       printf( "按其它键无效\n" );

             scanf( "%d", &flag );

   }

         if( flag==0 )

         break;

 

          goto loop;

 

 

    }

 }

int question_get()

{

   int a,b,c;

  loop: if( type==1 )

     {

        a=rand()%99;

        b=99-a;

        b=rand()%b;

        printf( "%d + %d = ?", a, b );

        return(a+b);

      }

   else if( type==2 )

     {

        b=rand()%99;

        c=99-b;

        c=rand()%c;

        printf( "%d - %d = ?", b+c, b );

        return(c);

      }

   else if( type==3 )

     {

       a=rand()%10;

       b=50-a;

       b=rand()%b;

       printf( "%d * %d = ?", a, b );

       return(a*b);

      }

   else if( type==4 )

     {

       b=rand()%50;

       c=100/b;

       while( 1 )

       {

          c=rand()%c;

          if( c!=0 )

              break;

       }

       printf( "%d / %d = ?", b*c, b );

       return(c);

      }  

   else if( type==5 )

     {

       printf("\t\t\t退出系统\n"); /*结束程序*/

       system("pause");

       exit(0);

      }

   else if( type==0||type>5 )

      {

        printf("\t\t\t输入错误,请输入1-5内的数字\n");

        printf("\t\t\t请选择(1-5):");

        scanf( "%d", &type );

        goto loop;

       }

 }

 

以上是关于个人项目3的主要内容,如果未能解决你的问题,请参考以下文章

个人项目3

地铁个人项目

个人项目3

个人项目3

个人项目3

07 个人项目3