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 11 2230
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.333333333333 3"
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....@gm ail.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.333333333333 3"
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....@gm ail.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.333333333333 3" 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<iostre am>
#include<iomani p>
using namespace std;
const double d=1.0/3.0;
int main() {
cout << fixed << setprecision(2) << d << ' '
<< setprecision(10 ) << d << endl;
}
HTH,
- J.
On Mar 5, 7:35 am, "arnuld" <geek.arn...@gm ail.comwrote:
On Mar 5, 10:25 am, Jacek Dziedzic <jacek.dziedzic .n.o.s.p....@gm ail.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.333333333333 3"
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
On Mar 5, 12:06 pm, Jacek Dziedzic <jacek.dziedzic _n.o.s.p.a....@ gmail.com.nospa m>
Try harder.
#include<iostre am>
#include<iomani p>
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.
arnuld wrote:
>On Mar 5, 12:06 pm, Jacek Dziedzic <jacek.dziedzi c_n.o.s.p.a.... @gmail.com.nosp am>
> Try harder.
#include<iostr eam> #include<ioman ip>
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.
On Mar 5, 2:09 pm, Jacek Dziedzic <jacek.dziedzic _n.o.s.p.a....@ gmail.com.nospa m>
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.
?
arnuld wrote:
>On Mar 5, 2:09 pm, Jacek Dziedzic <jacek.dziedzi c_n.o.s.p.a.... @gmail.com.nosp am>
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", "setprecisi on" and "manipulato rs".
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.
On Mar 5, 4:06 pm, Jacek Dziedzic <jacek.dziedzic _n.o.s.p.a....@ gmail.com.nospa m>
One way would be to google for "fixed", "setprecisi on" and "manipulato rs".
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
:-) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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.
Any ideas how to solve this (other than using 'filterwarnings')?
Thanks.
|
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 from the same ASP page.
|
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 worked very well a long time, but now it does not work anymore.
We use IE6 and Microsoft Windows XP Professional 2002 SP2.
I guess it has something to do with new IE security features. Does
|
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 C#. However, it's a
real hassle that the book has no index, just a table of contents.
For example, as early as page 8, the book teaches that C#'s "using"
statement is the equivalent of VB.NET's "imports" statement. However,
that concept...
|
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 leads to the second question. I got the "Conversion
buffer overflow" error when I run the following code:
Stream s = openFileDialog1.OpenFile();
| |
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 could no longer edit it in older versions
of Visual Studio.
What does this conversion entail. It seems like a 1 way path.
|
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 throwing an exception. Is
there a plan at Microsoft VB .NET team to include a keyword equivalent to
"as"?
|
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?
Public Sub SaveAs(ByVal strPath As String)
|
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 and disable
"Automatic ANSI to OEM conversion":
- This only affects isql from the command line, and no gui
applications
- http://support.microsoft.com/?scid=kb;EN-US;153449
- Start the "Client Network Utility"
C:\WINDOWS\system32\cliconfg.exe
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |