#include <iostream.h>
int x=-80;
int y=0; //cannot equal zero due to the for loop
int i=0;
void main()
{
cout << "x" << " " << "i" << " " << "y" << endl;
do
{
i=x; //x must be constant for incrementation
cout << x << " " << i << " " << y << endl; //debug
i=((5/9)(i-32));//formula for finding a celsius temperature from a farenheight one
x++; //increment x
cout << x << " " << i << " " << y <<endl; //debug
cout << endl; //debug
}while(y!=x);
cout << "The values of Celsius and Farenheight are equal at: " << y << " degrees." << endl;
}
It is supposed to find the value at which celsius and farenheight are equal, which I know is -40 but cannot hardcode into the program. I thought this would work, but every time I run it, my debug output statements show that i is being set to 0 after the equation to find the celsius temperature has concluded. When I took out the 5/9 part, it began changing values. Why is this? I've tried making the variables all floats, but it doesn't change anything.
If you don't want to use floating points, just do the multiplication first:
1 2 3 4
int boilingF = 212;
int boilingC = (boilingF - 32) * (5 / 9); // bad, is zero
boilingC = (boilingF - 32) * 5 / 9; // OK, multiplication is first, so not zero.