Here is my code:
//celsius.cpp
//demonstrates cin, newline
//a personal experiment, not a part of a book
//converts from celsius to fahrenheit
#include <iostream>
#include <conio.h>
using namespace std;
int main ()
{
int ctemp; //for temperature in celsius
cout << "Enter temperature in celsius: ";
cin >> ctemp;
int ftemp = 32 + ((9 / 5) * ctemp);
cout << "Equivalent in fahrenheit is: " << ftemp << '\n';
getch();
return 0;
}
Ok, when I run this program and I input 100 I should get 212, but instead I get 132. I'm guessing that for some reason the program is just adding 32 to ctemp and ignoring the (9 / 5) * part for some reason. Would anyone mind explaining that reason to me?
Thanks!
Note: When I write the equation like this: ctemp * 9 / 5 + 32 it works perfectly. But I wrote it a bunch of ways, without any parentheses and with, and that is the only way that worked. I'm really curious as to why.

New Topic/Question
Reply




MultiQuote




|