Conversion Farenheit Celsius

Asked

Viewed 58 times

0

Make an algorithm that calculates and writes a table of centigrade against degrees Farenheit, ranging from 50 to 150 of 1 in 1 I found the solution in C not in C++,

#include <iostream>
using namespace std;

int main()
{

    for (float F = 50; F < 150; F++) {
        float Ce;
        Ce = (5 / 9) * (F - 32);
        cout << "\nFarenheit " << F << "\nCentigrados  " << Ce;
    }
} 
  • for (float F = 50; F > 150; F++), why F > 150?

  • It’s to make a sequence

  • Exactly, but why did you put in for F > 150? You know how the for and what is each parameter?

  • Repeat until F is greater than 150

  • What do I know little

  • The syntax of for should be read as "repeat while"

  • So the right one is F<150

  • worked out that part, the problem now is the centigrados

  • Farenheit 50 Centigrados 0 Farenheit 51 Centigrados 0 Farenheit 52 Centigrados 0

Show 4 more comments

1 answer

2


When dividing an integer by an integer, the result will also be an integer. That is, if you divide 5 by 9, being both integers, you will have 0 as the whole part of the actual result. Thus, regardless of the value of F, you will always multiply by zero, which justifies your output being always zero.

If you need a real division, use at least one of the operands as real.

C = (5.0/9)*(F-32)
  • Thank you very much helped me

Browser other questions tagged

You are not signed in. Login or sign up in order to post.