I can't figure out why my code is rounding to a wrong number.
I am doing practice problem for an online course and I copied a code from my class. This is a program for converting fahrenheit to celsius. They spoke about saving fahrenheit and celsius as an integer on purpose to illustrate how the program will round.
Code:
#include <stdio.h>
int main(void)
{
int fahrenheit, celsius;
printf("Please enter fahrenheit as an integer:");
scanf("%d", &fahrenheit);
celsius = (fahrenheit - 32)/1.8; //Why is this converting to 99?
printf("\n%d fahrenheit is %d celsius.\n", fahrenheit, celsius);
return 0;
}
For some reason when I enter 212 as the Fahrenheit, I get 99 as an answer in Celsius. I thought because I divided celsius by 1.8 it should do the conversion as a double but then get rounded back to an integer when saved in celsius. I keep getting 99 as an answer. If I do the math, it should be (212-32)=180 then 180/1.8=100 Sorry for the newbie question but I am confused as this was supposed to be a lesson on how things get rounded when you use different data types. I am new to coding and don't understand what is happening.