返回   cpper编程论坛 > Zion/测试
注册账号 论坛帮助 会员列表 日历事件 搜索 今日新帖 标记版面已读

Zion/测试 惹人烦的东西这边来

回复
 
LinkBack 主题工具 显示模式
  #1 (permalink)  
旧 2005-05-16
up2009 的头像
普通会员
 
注册日期: 2005-05-11
帖子: 37
up2009 正向着好的方向发展
默认 初学者请教之二!

#include <iostream>
#include <string>
using namespace std;

int main()
{
string user_name;
int user_number=0,num_tries=0,num_right(0);
double user_score=0.0;
char user_more,user_rsp;
cout<<"please enter your name:";
cin>>user_name;
cout<<"\n";
cout<<"dear"<<user_name <<",请根据费氏数列,前两之和的第三数,第三数与第二数相加得第四数,"
<<"第四数与第五数相加的第五数,依次类推。"
<<"请输入下一数.\n";
int a,b;
a=1,b=1;
while (user_more!=true)
{
num_tries++;
cout<<a<<"+"<<b<<"=";
cin>>user_number;
cout<<"dear"<<user_name<<",您输入的答案是:"<<user_number<<"\n";
if (user_number==a+b)
// num_right++;
cout<<"恭喜你答对了!";

else
cout<<"你错了,正确的答案是:"<<a+b;
cout<<"\n"<<"try another sequence?y/n"<<endl;
cin>>user_rsp;
cout<<'\n';
if(user_rsp=='y' || user_rsp=='Y')
user_more=false;
else
/*user_score=num_right/num_tries;
cout<<"dear"<<user_name<<",本次练习共"<<num_tries<<"次"
<<"其中对的为"<<num_right<<"次,正确率为" <<user_score<<",请再接再厉!/n" ;*/
return 0;
}
return 0;


/* cout<<"f:\\a";
cin>>user_more;
bool go_for_it=true;
const int max_tries=3;
const double pi=3.14159;


return 0;*/
}
就是红色的"//"那一行,我加了后不能编译,说else语句错误,请教!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #2 (permalink)  
旧 2005-05-16
carol 的头像
高级会员
 
注册日期: 2004-07-29
住址: 苏州
帖子: 225
carol 正向着好的方向发展
发送 MSN 消息给 carol
默认

。。。 。。。你真走运居然碰到我今天心情好

if (user_number==a+b) {
num_right++;
cout<<"恭喜你答对了!";
}
else
...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #3 (permalink)  
旧 2005-05-16
carol 的头像
高级会员
 
注册日期: 2004-07-29
住址: 苏州
帖子: 225
carol 正向着好的方向发展
发送 MSN 消息给 carol
默认

我冒险再乱说两句

if ... else 语句的标准结构应该是
if (条件)
{
... 语句
}
else
{
... 语句
}
如果语句只有一句的话,大括号可以省略,其他情况下不可以省略。为了避免不小心产生这种错误,建议就算一句话也要加上大括号。
你这里面还有好多地方漏掉了,最好都检查一遍。
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #4 (permalink)  
旧 2005-05-16
up2009 的头像
普通会员
 
注册日期: 2005-05-11
帖子: 37
up2009 正向着好的方向发展
默认

非常感谢!
I SEE.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #5 (permalink)  
旧 2005-05-17
up2009 的头像
普通会员
 
注册日期: 2005-05-11
帖子: 37
up2009 正向着好的方向发展
默认

#include <iostream>
using namespace std;

int main()
{
int a=1,b=2 ,ab,c;
float ba;
//ab=a+b;
//ab=a-b;
ab=a*b ;
ba=a/b;
cout<<ab ;
cout<<ba;
cout<<"\n"<<"c=";
cin>> c;
if(c='q')

return 0;
}


运行结果:ab=2,
ba=0
请教我怎样才能把ba=0.5或ba=50%表达出来;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #6 (permalink)  
旧 2005-05-17
lxcLinuxer 的头像
初级会员
 
注册日期: 2005-01-03
帖子: 24
lxcLinuxer 正向着好的方向发展
默认

ba = (float)a/b
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #7 (permalink)  
旧 2005-05-18
up2009 的头像
普通会员
 
注册日期: 2005-05-11
帖子: 37
up2009 正向着好的方向发展
默认

thans !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
回复

书签
主题工具
显示模式

发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码
Trackbacks are 启用
Pingbacks are 启用
Refbacks are 启用



所有时间均为格林尼治时间 +9。现在的时间是 02:19 AM


Powered by vBulletin® 版本 3.7.0
版权所有 ©2000 - 2009,Jelsoft Enterprises Ltd.
(C) Copy Right All Right Reserved 2001 - 2007

Search Engine Friendly URLs by vBSEO 3.1.0