#include <stdio.h>
#include <iostream.h>
#include <stdlib.h>
int main(){
int result,x1,x2;
int temp;
double right,total;
char choose;
right = 0;
total = 0;
_1:
x1 = rand()%10;
x2 = rand()%10;
cout << "How much is "<< x1 <<" times " << x2 <<" ?"<<endl;
cin >> result;
total ++;
temp = rand()%4;
if(result == x1*x2){
right ++;
switch (temp){
case 0: cout<<"Very good!"<<endl;break;
case 1: cout<<"Excellent!"<<endl;break;
case 2: cout<<"Nice work!"<<endl;break;
case 3: cout<<"Keep up the good work!"<<endl;break;
}
}else{
switch (temp){
case 0: cout<<"NO.Please try again."<<endl;break;
case 1: cout<<"Wrong.Try once more."<<endl;break;
case 2: cout<<"Don't give up!"<<endl;break;
case 3: cout<<"NO.Keep trying."<<endl;break;
}
}
_2: cout<<"please choose: 1.continue 2.exit "<< endl;
cin >> choose;
switch(choose){
case '1': goto _1;
case '2': cout <<"your right rate is :"<<100*right/total<<"% ."<<endl;
if((right/total) < 0.75)
cout <<"Please ask your instructor for extra help!"<<endl;
return 0;
default: cout << "bad input! put in again!" <<endl;
goto _2;
}
}
流程就是这样了 不过要C的话 把cin cout换成 scanf 和 printf就可以了