• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

Program Help C++

FoxGaming

Exalted Member
I have been assigned to make a program to convert Fahrenheit to Celsius, I'm programming everything in RedHat with g++ as my compiler. Everything functions proper except when I run my program against the testBed. When the user enters in 0 for Fahrenheit the testBed says i should be getting -18 degrees Celsius, however it is rounding down and i'm getting -17. Currently my program is passing 4/5 of the testBed tests, which is still a B. I'd still like to figure this out though.

I can provide a windows solution if anyone would rather have it, though there is really no difference.

Code:
#include <iostream>
#include <iomanip>
using namespace std;

/**********************************************************************
 * Add text here to describe what the function "main" does. Also don't forget
 * to fill this out with meaningful text or YOU WILL LOSE POINTS.
 ***********************************************************************/
int main()
{
   cout.setf(ios::fixed);
   cout.precision(0);
   cout << "Please enter Fahrenheit degrees: ";
   int Far;
   cin >> Far;
   int C = 5.0 / 9 * (Far - 32);
   cout << "Celsius: " << C
        << endl;
   return 0;
}
 

Tommy

Founder
If I'm correct, 0 degree Fahrenheit is still in the range of -17 Celsius, around -17.7. However, rounding it off would be -18 Celsius..

I believe it will get you -18 degrees if you change "int C" to "double C", considering it isn't even at -17 Celsius.

nbIHQTP.png


Tested it myself. \o/

Also, WHY AM I DOING YOUR HOMEWORK BRO!?
 
Last edited:

FoxGaming

Exalted Member
If I'm correct, 0 degree Fahrenheit is still in the range of -17 Celsius, around -17.7. However, rounding it off would be -18 Celsius..

I believe it will get you -18 degrees if you change "int C" to "double C", considering it isn't even at -17 Celsius.

nbIHQTP.png


Tested it myself. \o/

Also, WHY AM I DOING YOUR HOMEWORK BRO!?

haha thanks all for the help, the error was changing int to double though I don't really get why my professor would want it to say -18 when it's not, personally i would much rather just show decimals.

it'll be the last homework help I post lol SORRY the next one will be in disguise, I was just stuck at the last part and couldn't figure it out.
 

Tommy

Founder
haha thanks all for the help, the error was changing int to double though I don't really get why my professor would want it to say -18 when it's not, personally i would much rather just show decimals.

it'll be the last homework help I post lol SORRY the next one will be in disguise, I was just stuck at the last part and couldn't figure it out.

I'm assuming he isn't a professor that likes to be specific. I would want everyone to know the CORRECT way instead of replacing that with ignorance. Glad I could help, it is what I do. :thoughtful:
 

FoxGaming

Exalted Member
I'm assuming he isn't a professor that likes to be specific. I would want everyone to know the CORRECT way instead of replacing that with ignorance. Glad I could help, it is what I do. :thoughtful:

He definitely isn't specific, it's awful. He doesn't teach either, I've got a textbook, some online links, and access to my own Linux VPS, that's how we're supposed to learn, it's definitely an interesting class. That and I got the worst professor lol
 

Hyperion

Founder
He definitely isn't specific, it's awful. He doesn't teach either, I've got a textbook, some online links, and access to my own Linux VPS, that's how we're supposed to learn, it's definitely an interesting class. That and I got the worst professor lol

Then I'm sure he just wants the same answer from you that's in the textbook? That's lazy teaching IMO :p
 

FoxGaming

Exalted Member
Yup, like I can write the code however I want but it must match the output 100% when it's tested against what is expected. Which I don't think is right, but I have learned a few things by taking lessons in the textbook and writing my own programs i think i've made like 10 in 2 weeks, neither of them is very large they're mostly calculators and stuff like that but I would've been stumped by this task a few weeks ago so i guess i'm learning just not really the way that would be most beneficial.
 

Tommy

Founder
Yup, like I can write the code however I want but it must match the output 100% when it's tested against what is expected. Which I don't think is right, but I have learned a few things by taking lessons in the textbook and writing my own programs i think i've made like 10 in 2 weeks, neither of them is very large they're mostly calculators and stuff like that but I would've been stumped by this task a few weeks ago so i guess i'm learning just not really the way that would be most beneficial.

If the output isn't correct and he wants you to do it the wrong way, do it both ways (correct/wrong) and show him. :p
 
Top