| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 511 人关注过本帖
标题:[讨论] 折磨我N久的一道貌似很简单的一道题!不要小看哦!
只看楼主 加入收藏
enchk
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2006-9-23
收藏
 问题点数:0 回复次数:2 
[讨论] 折磨我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”,
然后结束程序运行。

搜索更多相关主题的帖子: 正确答案 trying 百分比 color 
2007-04-17 10:02
I喜欢c
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:64
帖 子:1749
专家分:0
注 册:2007-3-2
收藏
得分:0 

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


 我是指针,却丢失了目标地址!          我是循环,却缺少了结束条件!      我是函数,却没有人来调用!   
2007-04-17 12:40
sunspirit
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2007-4-10
收藏
得分:0 

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

2007-04-17 16:27
快速回复:[讨论] 折磨我N久的一道貌似很简单的一道题!不要小看哦!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019972 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved