0

I don't understand why the following formula doesn't compute as it should.

F = (9/5) * C + 32

And when the "9/5" is replaced by 1.8, there aren't any issues and it correctly outputs like this:

Enter the temperature: 37
It is same as 98.6

But for (9/5) it shows:

Enter the temperature: 37
It is same as 69

Why is that??

Below is the code:

#include <iostream>
using namespace std;

int main() {
    float Temp_C;
    cout << "Enter the temperature: ";
    cin >> Temp_C;
    cout << "It is same as " << (((9/5) * Temp_C) + 32) << endl;             
}
  • 2
    Use `(9.0/5.0)` - so the compiler will see that these are the float values. 9/5 as integers gives you 1. – Michael Mar 04 '22 at 01:42
  • `9/5 == 1` in C++. – Silvio Mayolo Mar 04 '22 at 01:44
  • To expand on the above, Here's some documentation on [Integer literals](https://en.cppreference.com/w/cpp/language/integer_literal) and [Floating point literals](https://en.cppreference.com/w/cpp/language/floating_literal). – user4581301 Mar 04 '22 at 01:53

0 Answers0