当前位置: 代码迷 >> C语言 >> [讨论] 折磨我N久的一道貌似很简单的一道题!不要小看哦!
  详细解决方案

[讨论] 折磨我N久的一道貌似很简单的一道题!不要小看哦!

热度:247   发布时间:2007-04-17 10:02:24.0
[讨论] 折磨我N久的一道貌似很简单的一道题!不要小看哦!

使用rand生成两个正的一位整数,显示如下问题:How much is 6 times 7?
对正确答案的回应信息:
Very good!
Excellent!
Nice work!
Keep up the good work!
对错误答案的回应信息:
NO.Please try again.
Wrong.Try once more.
Don't give up!
NO.Keep trying.
使用随即数生成程序来选择从1~4之间的数字,以选择每个答案的回应信息。
使用带有printf语句的switch结构来发出这些回应信息。
计算出输入的正确答案的百分比,若百分比低于75%,程序输出“Please ask your instructor for extra help”,
然后结束程序运行。


----------------解决方案--------------------------------------------------------

把你写 的程序发出来看有什么问题.....
大家讨论讨论~``


----------------解决方案--------------------------------------------------------

#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就可以了


----------------解决方案--------------------------------------------------------
  相关解决方案