“cout”有什么问题句法??试用计划 [英] what is wrong with "cout " syntax?? a trial program

查看:82
本文介绍了“cout”有什么问题句法??试用计划的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有以下代码可以通过

指定值来增加功率。

int main()< br $>
{


system(" cls");

int i,exponent;

double base;

double new_base = 0.0;

ofstream powerfile(" power.txt",ios :: app);

cout< <"输入基数:\ n";

cin> base;

cout<<"输入指数:\ n" ;;

cin> exponent;

// cout<<基础;

for(i = 0; i< exponent; i ++)

{

new_base = new_base + base;


}

cout<<"最终的动力输出是:\ n" << new_base;

system(" PAUSE");

返回0;


}

但是屏幕上显示的输出是:

最终的动力输出是:

3.32222e-31204(一些奇怪的值)。

每次输入。

可能是什么原因?

提前致谢

Hi all,
I have following code that is supposed to increase the power by
specified value.
int main()
{

system("cls");
int i, exponent;
double base;
double new_base=0.0;
ofstream powerfile("power.txt",ios::app);
cout <<"Enter the base:\n";
cin >base;
cout <<"Enter the exponent:\n";
cin >exponent;
//cout << base;
for (i=0; i< exponent ; i++)
{
new_base = new_base + base;

}
cout <<"The final powered output is :\n" << new_base;
system("PAUSE");
return 0;

}
but the output that shows up in the screen is:
The final powered output is :
3.32222e-31204 (some weird value).
for every input.
What could be the reason for that??
Thanks in advance

推荐答案

mahesh写道:
mahesh wrote:

大家好,

我有以下代码可以增加功率

指定值。
Hi all,
I have following code that is supposed to increase the power by
specified value.



似乎这里缺少一些包含....

Seems some includes are missing here....


int main()

{


system(" cls");

int i,exponent;

double base;
int main()
{

system("cls");
int i, exponent;
double base;



您最好初始化您尝试读取的变量。如果你没有b $ b,如果阅读失败,他们的价值将保持不确定。

You better initialise the variables you attempt to read. If you
don''t, their value will stay indeterminate if reading fails.


double new_base = 0.0;

ofstream powerfile(" power.txt",ios :: app);
double new_base=0.0;
ofstream powerfile("power.txt",ios::app);



这是为了什么?你似乎没有使用它......

What''s that for? You don''t seem to be using it...


cout<<"输入基数:\ n";

cin> base;

cout<<"输入指数:\ n" ;;

cin> exponent;

// cout<<基础;
cout <<"Enter the base:\n";
cin >base;
cout <<"Enter the exponent:\n";
cin >exponent;
//cout << base;



你确定这些值是你输入的吗?

Are you sure the values are what you enter?


for(i = 0; i< exponent; i ++)

{

new_base = new_base + base;


}

cout< ;<"最终的动力输出是:\ n << new_base;

system(" PAUSE");

返回0;


}

但是屏幕上显示的输出是:

最终的动力输出是:

3.32222e-31204(一些奇怪的值)。

每次输入。

原因可能是什么?
for (i=0; i< exponent ; i++)
{
new_base = new_base + base;

}
cout <<"The final powered output is :\n" << new_base;
system("PAUSE");
return 0;

}
but the output that shows up in the screen is:
The final powered output is :
3.32222e-31204 (some weird value).
for every input.
What could be the reason for that??



该程序显然无法读取您的值,在这种情况下

''base''变量保持未初始化。请将其初始化为

,并确认您所读取的值与

不同,您初始化它(并且对您的计算有效)。


V

-

请在通过电子邮件回复时删除资金''A'

我这样做没有回复最热门的回复,请不要问

The program apparently fails to read your value, in which case
''base'' variable stays UNinitialised. Please initialise it to
something and verify that the value you read is different from
what you initialise it to (and valid for your calculations).

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


几点。


不应该:

new_base = new_base + base be new_base = new_base * base


(只是一个建议)

另外,你有什么输入尝试过吗?像这样的大负数指数

通常表示所谓的浮点

不精确。一般来说,你只会在0左右注意到这一点,并且它b / b
来自浮点显示非常大的b $ b b数或非常小的能力。想想科学数字。一个预期为零的操作

并不一定最终会以
零结束。


最后的问题但是,你有stdio,对吗?


6月20日下午1:20,mahesh< maheshr ... @ gmail.comwrote:
A couple points.

Shouldn''t:
new_base = new_base + base be new_base = new_base * base

(just a suggestion)
Also, what inputs have you tried it with? A large negative exponent
like that is often a sign of what is known as floating point
imprecision. Generally, you''ll only notice this around 0, and it
comes from the ability of the floating point to show very large
numbers or very very small. Think scientific numbers. An operation
that it expects to be a zero doesn''t necessarily actually end up at
zero.

Final question though, you DO have stdio included, right?


On Jun 20, 1:20 pm, mahesh <maheshr...@gmail.comwrote:

大家好,

我有以下代码可以通过

指定值来增加功率。

int main()

{


system(" cls");

int i,exponent ;

双基;

double new_base = 0.0;

ofstream powerfile(" power.txt",ios :: app);

cout<<"输入基数:\ n" ;;

cin> base;

cout<<" ;输入指数:\ n" ;;

cin> exponent;

// cout<<基础;

for(i = 0; i< exponent; i ++)

{

new_base = new_base + base;


}

cout<<"最终的动力输出是:\ n" << new_base;

系统(PAUSE);

返回0;


}


但是屏幕上显示的输出是:

最终的动力输出是:

3.32222e-31204(一些奇怪的值)。

每次输入。

可能是什么原因?

先谢谢
Hi all,
I have following code that is supposed to increase the power by
specified value.
int main()
{

system("cls");
int i, exponent;
double base;
double new_base=0.0;
ofstream powerfile("power.txt",ios::app);
cout <<"Enter the base:\n";
cin >base;
cout <<"Enter the exponent:\n";
cin >exponent;
//cout << base;
for (i=0; i< exponent ; i++)
{
new_base = new_base + base;

}
cout <<"The final powered output is :\n" << new_base;
system("PAUSE");
return 0;

}

but the output that shows up in the screen is:
The final powered output is :
3.32222e-31204 (some weird value).
for every input.
What could be the reason for that??
Thanks in advance



mahesh写道:
mahesh wrote:

大家好,

我有以下代码可以增加通过

指定值。
Hi all,
I have following code that is supposed to increase the power by
specified value.



#include< iostream>

#include< fstream>

#include< cstdlib>

使用命名空间std;

#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;


int main()

{


system(cls);
int main()
{

system("cls");



这只是windows。

this is windows only.


int i,exponent;

双基;

double new_base = 0.0;

ofstream powerfile(" power.txt",ios :: app);

cout< ;<"输入基数:\ n";

cin> base;

cout<<"输入指数:\ n" ;

cin> exponent;

// cout<< base;

for(i = 0; i< exponent; i ++)
int i, exponent;
double base;
double new_base=0.0;
ofstream powerfile("power.txt",ios::app);
cout <<"Enter the base:\n";
cin >base;
cout <<"Enter the exponent:\n";
cin >exponent;
//cout << base;
for (i=0; i< exponent ; i++)



ni c ++,最好声明

for(int i = 0; ...

并删除主体开头的int i。

ni c++, it''s better to declare
for(int i = 0; ...
and remove the int i at the beginning of the main body.


{

new_base = new_base + base;
{
new_base = new_base + base;



它应该是一个乘法(new_base初始化为1.0),

不应该吗?

It should be a multiplication (with new_base initialized to 1.0),
shouldn''t it?


>

}

cout<< ;最终的动力输出是:\ n"<< new_base;

system(" PAUSE");
>
}
cout <<"The final powered output is :\n" << new_base;
system("PAUSE");



再次,它只有窗口

again, it''s only windows


返回0;


}

但是显示在屏幕上的输出是:

最终的动力输出是:

3.32222e-31204(有些奇怪的值)。

每个输入。
return 0;

}
but the output that shows up in the screen is:
The final powered output is :
3.32222e-31204 (some weird value).
for every input.



在我的系统中它运行正常。也许是一些iostream问题。您可以尝试在每个cin>>之后添加cin.sync(),以便从缓冲区中清除垃圾(\ n)

。 br />

In my system it works fine. Maybe some iostream issue. You can try to
add cin.sync() after each cin >>, in order to flush the garbage (\n)
from the buffer.


可能是什么原因?

提前致谢
What could be the reason for that??
Thanks in advance



问候,


Zeppe

Regards,

Zeppe


这篇关于“cout”有什么问题句法??试用计划的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆