473,320 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

a "temp conversion" programme

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

Mar 5 '07 #1
11 2207
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.
Mar 5 '07 #2
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"

Mar 5 '07 #3
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.
Mar 5 '07 #4
On Mar 5, 7:35 am, "arnuld" <geek.arn...@gmail.comwrote:
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"
They should work for doubles too.

--
Erik Wikström

Mar 5 '07 #5
On Mar 5, 12:06 pm, Jacek Dziedzic <jacek.dziedzic_n.o.s.p.a....@gmail.com.nospam>
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;

}

Erm... and i was using "d.precision(3)".

BTW, i removed "fixed" from your code. i does not make any difference.

Mar 5 '07 #6
arnuld wrote:
>On Mar 5, 12:06 pm, Jacek Dziedzic
<jacek.dziedzic_n.o.s.p.a....@gmail.com.nospam>
> 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;

}


Erm... and i was using "d.precision(3)".

BTW, i removed "fixed" from your code. i does not make any difference.
Sure it does, you just didn't notice. I'll let you figure it out,
though. Try this

#include <iostream>
#include <iomanip>

using namespace std;

int main() {
cout << setprecision(3) << 123.456 << ' ' << fixed
<< setprecision(3) << 123.456 << endl;
}

- J.

Mar 5 '07 #7
On Mar 5, 2:09 pm, Jacek Dziedzic <jacek.dziedzic_n.o.s.p.a....@gmail.com.nospam>
BTW, i removed "fixed" from your code. i does not make any difference.

Sure it does, you just didn't notice. I'll let you figure it out,
though. Try this

#include <iostream>
#include <iomanip>

using namespace std;

int main() {
cout << setprecision(3) << 123.456 << ' ' << fixed
<< setprecision(3) << 123.456 << endl;

}
yes, i noticed now. the output of your programme is: 123 123.456

now here is some interesting pattern:

1.)
<< setprecision(3) << 123.456
<< fixed
<< ' '
<< setprecision(3) << 123.456
OUTPUT: 123 123.456

here i have use /fixed/ as like a prefix

2.)
<< fixed
<< setprecision(3) << 123.456
<< ' '
<< setprecision(3) << 123.456
<< endl;

OUTPUT: 123.456 123.456

here 1 /fixed/ worked for both.
3.)
<< setprecision(3) << 123.456
<< ' '
<< setprecision(3) << 123.456
<< fixed
<< endl;

}

OUTPUT: 123 123

/fixed/ doe snot work here.
i want to know how exactly /fixed/ work, in context to patterns 1,2
and 3.

?

Mar 5 '07 #8
arnuld wrote:
>On Mar 5, 2:09 pm, Jacek Dziedzic
<jacek.dziedzic_n.o.s.p.a....@gmail.com.nospam>
BTW, i removed "fixed" from your code. i does not make any difference.

Sure it does, you just didn't notice. I'll let you figure it out,
though. Try this

#include <iostream>
#include <iomanip>

using namespace std;

int main() {
cout << setprecision(3) << 123.456 << ' ' << fixed
<< setprecision(3) << 123.456 << endl;

}

yes, i noticed now. the output of your programme is: 123 123.456

now here is some interesting pattern:

1.)
<< setprecision(3) << 123.456
<< fixed
<< ' '
<< setprecision(3) << 123.456
OUTPUT: 123 123.456

here i have use /fixed/ as like a prefix

2.)
<< fixed
<< setprecision(3) << 123.456
<< ' '
<< setprecision(3) << 123.456
<< endl;

OUTPUT: 123.456 123.456

here 1 /fixed/ worked for both.
3.)
<< setprecision(3) << 123.456
<< ' '
<< setprecision(3) << 123.456
<< fixed
<< endl;

}

OUTPUT: 123 123

/fixed/ doe snot work here.
i want to know how exactly /fixed/ work, in context to patterns 1,2
and 3.
One way would be to google for "fixed", "setprecision" and "manipulators".

Consulting your favourite C++ textbook would be another.

Anyway, fixed did not work in your last example, since it was
output _after_ your numbers. They were output already, so it had
no chance to act.

Anyway 2, with 'fixed' the 'setprecision' manipulator tells the
stream how many digits after the decimal point you want to output,
without fixed it tells how many digits _total_ you want to output.

HTH,
- J.
Mar 5 '07 #9
On Mar 5, 4:06 pm, Jacek Dziedzic <jacek.dziedzic_n.o.s.p.a....@gmail.com.nospam>

One way would be to google for "fixed", "setprecision" and "manipulators".

i did that after reading your reply. sorry...

i found one more manipulator named /scientific/ an opposite of /
fixed/
Consulting your favourite C++ textbook would be another.
yes, i tried Stroustrup before posting here my 3 patterns but it did
not tell me anything useful, totally unlike Google.

Anyway, fixed did not work in your last example, since it was
output _after_ your numbers. They were output already, so it had
no chance to act.

Anyway 2, with 'fixed' the 'setprecision' manipulator tells the
stream how many digits after the decimal point you want to output,
without fixed it tells how many digits _total_ you want to output.

yes, i understood now, except one thing. from pattern '2' above, does
one /fixed/ works for all subsequent /setprecision(s)/

?

HTH,
of course that helped

:-)

Mar 5 '07 #10
arnuld wrote:
>On Mar 5, 4:06 pm, Jacek Dziedzic <jacek.dziedzic_n.o.s.p.a....@gmail.com.nospam>

> One way would be to google for "fixed", "setprecision" and "manipulators".


i did that after reading your reply. sorry...

i found one more manipulator named /scientific/ an opposite of /
fixed/
Almost an opposite. In fact you have three modes -- the default
(not fixed and not scientific), fixed and scientific.
yes, i understood now, except one thing. from pattern '2' above, does
one /fixed/ works for all subsequent /setprecision(s)/
Yes, as long as they are on the same output stream.

HTH,
- J.
Mar 5 '07 #11
On Mar 6, 1:28 am, Jacek Dziedzic <jacek.dziedzic.n.o.s.p....@gmail.comwrote:
arnuld wrote:
i found one more manipulator named /scientific/ an opposite of /
fixed/

Almost an opposite. In fact you have three modes -- the default
(not fixed and not scientific), fixed and scientific.
yes, i understood now, except one thing. from pattern '2' above, does
one /fixed/ works for all subsequent /setprecision(s)/

Yes, as long as they are on the same output stream.
thanks Jacek
Mar 6 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Miki Tebeka | last post by:
Hello All, I'm shipping an application using py2exe. With Python2.3 it worked fine but when switching to Python2.4 I started getting "warning: string/unicode conversion" all over the place. ...
3
by: Arnaldo Martinez | last post by:
Hi, friends: I have an ASP page where an user enter a value and click the submit button. I want this value to be transfer to a session("temp") within the same page where I want to call it back...
10
by: Dieter Salath? | last post by:
Hi, in our webpage, a user could open a windows explorer to his temp directory with a simple link and usage of the file protocol: <a href="file://C:\temp" target="_blank">C:\temp</a> This...
8
by: Dgates | last post by:
Has anyone typed up an index for the O'Reilly book "C# and VB.NET Conversion?" I'm just learning C#, and often using this little book to see which VB.NET terms translate directly to some term in...
3
by: poifull | last post by:
Hi All, What is the proper way to read a binary file into a byte? I am using BinaryReader to read from a Stream and call the ReadByte method of the BinaryReader object. The method I'm using...
2
by: George Durzi | last post by:
Hey folks, I just installed VS .NET 2003 on top of Windows 2003 Server. I was opening a Web Project from source control, and got a warning that the project would have to be "converted", and that I...
5
by: Hayato Iriumi | last post by:
When converting a type to another using CType and if the type conversion fails, it throw an exception. However, in C#, there is a keyword "as" which only makes the variable Nothing (null) without...
2
by: Guoqi Zheng | last post by:
Dear sir, I am trying to save a binary data by below script, however,it always give me an error of "Could not find a part of the path "C:\temp\". " Any idea what I did wrong here? ...
1
by: Philip Bondi | last post by:
Hello to all SQL Server junkies who work with non-English characters: For people running scripts from the command line using ANSI files with special characters, it is very important to use isql...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.