帮小学生练习乘法<2>

来源:互联网 发布:手机淘宝id怎么查看 编辑:程序博客网 时间:2024/04/30 15:27
//No.6-test-6.57//帮小学生练习乘法<2> #include<iostream>#include<cstdlib>#include <Windows.h>using namespace std;//显示题目 int showTitle();//答对显示提示语void correct();//答错显示提示语 void error();int main(){    while(1)    {        int stdAnswer=showTitle();                  while(1)        {            cout<<"你的答案:";            int userAnser;            cin>>userAnser;            if(userAnser==stdAnswer)             {                correct();                Sleep(1000);                system("cls");                break;            }else            {                error();            }           }     }    return 0; }int showTitle(){           int num1=0+rand()%9;    int num2=0+rand()%9;    int answer=num1*num2;//正确答案     cout<<num1<<"*"<<num2<<"="<<endl;    return answer;                          } void correct(){    int num=1+rand()%4;    switch(num)    {        case 1:cout<<"Very good!"<<endl<<endl;break;        case 2:cout<<"Excellent!"<<endl<<endl;break;        case 3:cout<<"Nice work"<<endl<<endl;break;        case 4:cout<<"Keep up the good work!"<<endl<<endl;break;    }   }void error(){    int num=1+rand()%4;    switch(num)    {        case 1:cout<<"No.Please try again!"<<endl<<endl;break;        case 2:cout<<"Wrong.Try once more."<<endl<<endl;break;        case 3:cout<<"Don't give up!"<<endl<<endl;break;        case 4:cout<<"No.Keep trying."<<endl<<endl;break;    }   }

效果图如下
效果图