ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am working through K&R as extra practice for my classes. I am on exercise 1-4 (converting Celsius to Fahrenheit). I believe my code should be solid, but I just need some help checking my math. My code is this:
I am confident my code (in the sense of the actual C code) is right on track, however I would love it if someone could check my math. Thank you in advance!
this is the wrong equation. The correct equation is
Code:
fahr = ((celsius) * (9.0/5.0)) + 32.0;
Then the issue is caused the line
Code:
celsius = celsius + step;
being executed before the print. You will then have the issue of the first number being 18 and thus the whole thing looks wrong and werid. To fix this change
If you search for celsius to fahrenheit on DuckDuckGo, it shows a conversion box which states that 3C is 37.4F and 23C is 73.4F so something is wrong.
Your output (left-hand side) is rushing ahead of itself and upper is also not being respected. Check your code - the first line should have -17 in the first column.
Also, giving an answer as 135.0 gives the impression that the .0 is calculated with that level of precision. 27.0, for example, should be either 27 or e.g. 27.4 (it could of course be 27.0 but all of the results won't be y.0).
T(°F) = (T(°C) × 9/5) + 32
Using the above equation, work out why your formula is incorrect.
however this is wrong as well. I can't seem to figure out exactly what is wrong with my formula... this seems like it should be the correct math to solve this problem. I looked here: https://www.metric-conversions.org/t...fahrenheit.htm even to check my numbers. I am very confused as to why this isn't working...
I am confused about what is causing the output to be wrong. If I am correct this should give the desired output, I don't understand why the output is as it is.
With the greatest of respect, you're not carefully reading the answers you have been given. You've got the equation right now but both astrogeek and I have told you why column 1 is incorrect.
For a start, can you please return lower and upper to -17 and 148 so that the analysis of your results is easier.
I stepped to soon haha. My numbers appear to be off, I am not wanting the answer; however what is the cause? Is it operational, data type or wrong numbers?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.