回 帖 发 新 帖 刷新版面

主题:求助 新手学C++ 不知道程序哪里出错

# include<iostream>
using std::cout;
using std::cin;
using std::endl;

#include<ctime>
using std::time;

#include<cstdlib>
using std::rand;
using std::srand;
int mNumber()
{
    int num;
    num=rand()%9+1;
    return num;    
}
void wrongDisplay()
{
    int num;
    num=mNumber();
        switch(num)
    {
        case 1:
        case 2:
        case 3:
         cout<<"NO,please try again.";
         break;
        case 4:
        case 5:
         cout<<"Wrong. try once more.";
         break;
        case 6:
        case 7:
         cout<<"Dont Give UP!"; 
         break;
        case 8:
        case 9:
         cout<<"Keep trying.";
         break;
        default:
         cout<<"Incorrect Enter"<<endl;
}


void rightDisplay()
{
    int num;
    num=mNumber();
    switch(num)
    {
        case 1:
        case 2:
        case 3:
         cout<<"very good!";
         break;
        case 4:
        case 5:
         cout<<"Excellent!";
         break;
        case 6:
        case 7:
         cout<<"Nice work!"; 
         break;
        case 8:
        case 9:
         cout<<"Keep up the good work!";
         break;
        default:
         cout<<"Incorrect Enter"<<endl;
    }
    
}
int main(void)
{
    srand(time(0));
    int num1,num2,result,calculate;
    for(int i=0;i!=-1;)
    {
        num1=mNumber();
        num2=mNumber();
        result=num1*num2;
        cout<<num1<<"*"<<num2<<"=";
        cin>>calculate;
        while(calculate!=result)
        {
            wrongDisplay();
            cin>>calculate;
        }
        rightDisplay();
        cout<<"输入-1结束或任意键继续:";
        cin>>i;
    }
    return 0;
}

回复列表 (共2个回复)

沙发

就WrongDisplay()里的switch最后少个 }

板凳


谢谢 [em1]

我来回复

您尚未登录,请登录后再回复。点此登录或注册