“温度转换”程序 [英] a "temp conversion" programme

查看:76
本文介绍了“温度转换”程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个新的温度转换程序。它可以根据用户的意愿将华氏温度转换为摄氏温度或从摄氏温度转换为华氏温度值b $ b。告诉我们我是否需要一些改进:


//温度转换

//使用摄氏和华氏


#include< iostream>


int main(){

double centi;

double fahr;

char ans;


std :: cout<< 你想将摄氏度转换为华氏度:

[y / n];

std :: cin> ans;


if(ans ==''y'')

{

std :: cout<< 以摄氏温度输入温度:;

std :: cin> centi;


fahr =(9.0 / 5.0 * centi)+ 32;

std :: cout<< centi

<< "摄氏度="

<< fahr

<< " fahrenheit"

<< " \ n";

}


其他

{

std :: cout << 以华氏温度输入温度:;

std :: cin> fahr;


centi = 5.0 / 9.0 *(fahr - 32);

std :: cout<< fahr

<< " farenheit ="

<< centi

<< "摄氏度>

<< " \ n";

}


返回0;

}


- arnuld
http://arnuld.blogspot.com

解决方案

arnuld写道:


i创建了一个新的温度转换程序。它可以根据用户的意愿将华氏温度转换为摄氏温度或从摄氏温度转换为华氏温度值b $ b。告诉我们我是否需要一些改进:


//温度转换

//使用摄氏和华氏


#include< iostream>


int main(){

double centi;

double fahr;

char ans;


std :: cout<< 你想将摄氏度转换为华氏度:

[y / n];

std :: cin> ans;


if(ans ==''y'')

{

std :: cout<< 以摄氏温度输入温度:;

std :: cin> centi;


fahr =(9.0 / 5.0 * centi)+ 32;

std :: cout<< centi

<< "摄氏度="

<< fahr

<< " fahrenheit"

<< " \ n";

}


其他

{

std :: cout << 以华氏温度输入温度:;

std :: cin> fahr;


centi = 5.0 / 9.0 *(fahr - 32);

std :: cout<< fahr

<< " farenheit ="

<< centi

<< "摄氏度>

<< " \ n";

}


返回0;

}



嗯,你可以更好地格式化你的输出...

小数点后四舍五入到两位数怎么样?

这样你就不会''在你的输出中获得类似3.3333333333333

的值。


如果你有兴趣实现这个目标,那么#include

文件''iomanip''并查看操纵器

''fixed''和''setprecision''。


HTH,

- J.


3月5日上午10点25分,Jacek Dziedzic< jacek.dziedzic.nosp ... @ gmail.comwrote:


好​​吧,你可以更好地格式化你的输出...

小数点后四舍五入到两位数怎么样?

那样你就不会在你的输出中得到像3.3333333333333

这样的价值。


如果你是这样的话实现这一目标,#include

文件''iomanip''并查看操纵器

''fixed''和''setprecision''。



它们用于浮动。我试过了,你不能用它们来支付

双打


arnuld写道:
< blockquote class =post_quotes>


> 3月5日上午10点25分,Jacek Dziedzic< jacek.dziedzic.nosp ... @ gmail.com>
写道:


>好吧,你可以更好地格式化你的输出......
如何在小数点后四舍五入到这两个数字?
这样你就不会得到像3.3333333333333这样的值。您的输出。

如果您有兴趣实现这一目标,请#include
文件''iomanip''并查看操纵器
''fixed''和'' setprecision'。



他们用于浮动。我试过了,你不能用它们来支付

双打



更加努力。


#include< iostream>

#include< iomanip>


使用命名空间std;


const double d = 1.0 / 3.0;


int main( ){

cout<<固定<< setprecision(2)<< d<< ''''

<< setprecision(10)<< d<<结束;

}


HTH,

- J.


i have created a new temperature conversion programme. it converts a
temperature from Fahrenheit to Celsius or from Celsius to Fahrenheit
at user''s will. tell em if i need some improvements:

// conversion of temperature
// using Centigrade and Fahrenheit

#include <iostream>

int main() {
double centi;
double fahr;
char ans;

std::cout << "do you want to convert a Centigrade into Fahrenheit:
[y/n]";
std::cin >ans;

if(ans == ''y'')
{
std::cout << "Enter temperature in Centigrade: ";
std::cin >centi;

fahr = (9.0/5.0 * centi) + 32;
std::cout << centi
<< " centigrade = "
<< fahr
<< " fahrenheit"
<< "\n";
}

else
{
std::cout << "Enter temperature in Fahrenheit: ";
std::cin >fahr;

centi = 5.0/9.0 * (fahr - 32);
std::cout << fahr
<< " farenheit = "
<< centi
<< " centigrade"
<< "\n";
}

return 0;
}

-- arnuld
http://arnuld.blogspot.com

解决方案

arnuld wrote:

i have created a new temperature conversion programme. it converts a
temperature from Fahrenheit to Celsius or from Celsius to Fahrenheit
at user''s will. tell em if i need some improvements:

// conversion of temperature
// using Centigrade and Fahrenheit

#include <iostream>

int main() {
double centi;
double fahr;
char ans;

std::cout << "do you want to convert a Centigrade into Fahrenheit:
[y/n]";
std::cin >ans;

if(ans == ''y'')
{
std::cout << "Enter temperature in Centigrade: ";
std::cin >centi;

fahr = (9.0/5.0 * centi) + 32;
std::cout << centi
<< " centigrade = "
<< fahr
<< " fahrenheit"
<< "\n";
}

else
{
std::cout << "Enter temperature in Fahrenheit: ";
std::cin >fahr;

centi = 5.0/9.0 * (fahr - 32);
std::cout << fahr
<< " farenheit = "
<< centi
<< " centigrade"
<< "\n";
}

return 0;
}

Well, you could format your output better...
How about rounding to two digits after the decimal point?
That way you wouldn''t get values like "3.3333333333333"
in your output.

If you are interested in achieving this, #include
the file ''iomanip'' and look up on the manipulators
''fixed'' and ''setprecision''.

HTH,
- J.


On Mar 5, 10:25 am, Jacek Dziedzic <jacek.dziedzic.n.o.s.p....@gmail.comwrote:

Well, you could format your output better...
How about rounding to two digits after the decimal point?
That way you wouldn''t get values like "3.3333333333333"
in your output.

If you are interested in achieving this, #include
the file ''iomanip'' and look up on the manipulators
''fixed'' and ''setprecision''.

they are for "floats". i have tried that, you can not use them for
"doubles"


arnuld wrote:

>On Mar 5, 10:25 am, Jacek Dziedzic <jacek.dziedzic.n.o.s.p....@gmail.com>
wrote:

> Well, you could format your output better...
How about rounding to two digits after the decimal point?
That way you wouldn''t get values like "3.3333333333333"
in your output.

If you are interested in achieving this, #include
the file ''iomanip'' and look up on the manipulators
''fixed'' and ''setprecision''.


they are for "floats". i have tried that, you can not use them for
"doubles"

Try harder.

#include<iostream>
#include<iomanip>

using namespace std;

const double d=1.0/3.0;

int main() {
cout << fixed << setprecision(2) << d << '' ''
<< setprecision(10) << d << endl;
}

HTH,
- J.


这篇关于“温度转换”程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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