I need help with my program. The program reads water temperatures and when they were recorded from an input file called " biodata2.txt." Then the output is displayed in a file called "results.txt" So the input file looks like this:
2 // number of readings taken
200707211245 // date recorded
F70.5 // Fahrenheit temperature
200708220812// date recorded
C19.97// Celsius temperature
So, the program rearranges the data to look like this:
Number of Recordings found: 2
C19.97-- recorded on 08/21/2007 at 08:12, etc. for any other data records.
I am also supposed to convert all Fahrenheit readings to Celsius. This is were the problem is, I read in the temperature in Fahrenheit using "inFile >> temp" and input it into the formula with result being "celsius" variable. The out put I get is -0 instead of the correct answer. Can anyone help me?
Recommended Answers
Jump to PostMaybe post your formula for converting F to C?
You didn't do 5/9 by any chance, which would be 0
As opposed to say 5.0/9.0 which is nearer to what you want.
Jump to PostWhat's the output of temp before you use the function?
Any code to see how you're going about that?
Jump to PostHeh - 9/5, how about that then ^^^^^
Jump to PostError on conversion:
Sorry classic error:
int a=9; int b=5; // this gives 1 std::cout<<"Int division "<<a/b<<std::end;
The code you have written gives the error because of 9/5 == 1.
If you write 9.0/5.0 or even 9*(temp-32)/5 you would have the correct answer.[p.s. Sorry …
Jump to PostYou really need to work on your order of operations.
You need to do the subtraction first, then divide that number by the constant of 9/5(1.8); not 1.8 divided by the difference.
Go to the library and check out a book on Algebra, then do a few brief …
All 19 Replies
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.