C 新手问题,老手有空过来看看帮帮谢谢

[复制链接]
查看11 | 回复9 | 2011-3-13 10:41:51 | 显示全部楼层 |阅读模式
#include iostream
#include cmath
using std::cout;
using std::cin;
using std::sqrt;

int main(){
const double fish_factor=2.0/0.5;
const double pi_=3.14159265;

double fish_count=0.0;
double fish_length=0.0;

cout\"Enter the number of fish you want to keep:\";
cinfish_count;
cout\"Enter the average fish length in inches:\";
cinfish_length;
fish_length=fish_length/inches_per_foot;

double pond_arer=fish_count*fish_length*fish_factor;

double pond_diameter=2.0*sqrt(pond_area/pi);

cont\"\\n pond diameter required for\"fish_count\"fish is\"
pond_diameter\"feet.\\n\";
return 0;
}
书上的例子,cin不是要输入才能执行出结果吗?为什么执行文件执行的时候只是显示器黑了一会然后恢复正常,没有要求输入东西,有好心的老手能帮帮吗?如果时间指导下 QQ1164929227,不胜感激
回复

使用道具 举报

千问 | 2011-3-13 10:41:51 | 显示全部楼层
<pre id=\"best-answer-content\" class=\"reply-text mb10\">代码有很多错的地方,这是修正的~可能有的地方不是按你的要求来的:
#include iostream
#include cmath
using std::cout;
using std::cin;
using std::sqrt;

int main(){
const double fish_factor=2.0/0.5;
const double pi=3.14159265;//之前,这里pi多连了一个_,与后面引用时不符

double fish_count=0.0;
double fish_length=0.0;
double inches_per_foot;//这个是我加的,你在后面用到了,可是之前没有定义~
cout\"Enter the number of fish you want to keep:\";
cinfish_count;
cout\"Enter the average fish length in inches:\";
cinfish_length;
cout\"Enter inches_per_foot:\";//这一句和下一句都是我加的,因为后面用到了
cininches_per_foot;
fish_length=fish_length/inches_per_foot;//使用变量前必须先赋值~

double pond_area=fish_count*fish_length*fish_factor;

double pond_diameter=2.0*sqrt(pond_area/pi);

cout\"\\n pond diameter required for\"fish_count\"fish is\"
pond_diameter\"feet.\\n\";
return 0;
}
//还有几个地方,变量名不一致,我就不一一指出了,写程序仔细点~

















<h4 class=\"ask\">追问





<pre class=\"replyask-text\" id=\"content-1521325\">谢谢哈多谢,没分了
回复

使用道具 举报

千问 | 2011-3-13 10:41:51 | 显示全部楼层
<pre class=\"replyask-text\" id=\"content-1523845\">本来就是0分... ...采纳我的答案就行了~呵呵
回复

使用道具 举报

千问 | 2011-3-13 10:41:51 | 显示全部楼层
<pre class=\"replyask-text\" id=\"content-1261980\">编译出来是这个.exe - 0 error(s), 0 warning(s)呀,没错吧,照书上搬的
回复

使用道具 举报

千问 | 2011-3-13 10:41:51 | 显示全部楼层
<pre class=\"replyask-text\" id=\"content-1262024\">d:\\fitz\\documents\\visual studio 2008\\projects\\thetest\\thetest\\testencrypt.cpp(18) : error C2065: “inches_per_foot”: 未声明的标识符
1d:\\fitz\\documents\\visual studio 2008\\projects\\thetest\\thetest\\testencrypt.cpp(22) : error C2065: “pond_area”: 未声明的标识符
1d:\\fitz\\documents\\visual studio 2008\\projects\\thetest\\thetest\\testencrypt.cpp(22) : error C2065: “pi”: 未声明的标识符
1d:\\fitz\\documents\\visual studio 2008\\projects\\thetest\\thetest\\testencrypt.cpp(24) : error C2065: “cont”: 未声明的标识符
1生成日志保存在“file://d:\\Fitz\\Documents\\Visual Studio 2008\\Projects\\TheTest\\TheTest\\Debug\\BuildLog.htm”
回复

使用道具 举报

千问 | 2011-3-13 10:41:51 | 显示全部楼层
<pre class=\"replyask-text\" id=\"content-1262210\">你看这个代码有错吗
回复

使用道具 举报

千问 | 2011-3-13 10:41:51 | 显示全部楼层
<pre class=\"replyask-text\" id=\"content-1262385\">我这里的错误是四个没有声明的变量,不知道这些变量是打错了还是在哪里声明过,看不懂,所以不好说,只能说逻辑应该通,还是先解决语法错误吧。
回复

使用道具 举报

千问 | 2011-3-13 10:41:51 | 显示全部楼层
<pre class=\"replyask-text\" id=\"content-1262442\">宿舍熄灯了要,明天再整吧谢谢了哈
回复

使用道具 举报

千问 | 2011-3-13 10:41:51 | 显示全部楼层
<pre class=\"replyask-text\" id=\"content-1262505\">没事,慢慢来吧,我刚学的时候也遇到过不少问题,有的时候能抠好几天。
回复

使用道具 举报

千问 | 2011-3-13 10:41:51 | 显示全部楼层
<pre class=\"replyask-text\" id=\"content-1262348\">谢谢哈,错乱中呀
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行