A
A
Archpriest Metapop2020-08-10 13:22:25
C++ / C#
Archpriest Metapop, 2020-08-10 13:22:25

The C++ program works strangely. What to do?

#include <iostream>
using namespace std;
int main() {
    double fahr, cels;
    cout << endl <<  "Введите температуру по Фаренгейту" << endl;
    cin >> fahr;
    cels = 5 / 9 * (fahr - 32);
    cout << "По Фаренгейту: " << fahr << ", по Цельсию: " << cels << endl;
    return 0;
}

When you enter, say, the number 12, it says:
"Fahrenheit: 12, Celsius: 0"
What did I do wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2020-08-10
@caramel14

5 / 9 == 0 - both operands are integer, integer division.
5. / 9 == 5 / 9. == 5. / 9. == 0.555555556 - at least one of the operands is real, division is real.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question