mardi 17 janvier 2023

Output for C++ program is always -0 [duplicate]

I want to write a program that converts Fahrenheit into Celsius by function and running it through a for loop with i = 0, i <= 20, i++

I've made a function that converts Fahrenheit and celsius and put that in a for loop that goes through 0-20 with i being the argument for the function but the output of the loop is always -0

   #include <iostream>
   #include <cmath>
   using namespace std;
   double celsius(double f){
     return (5/9)*(f - 32);
   }
   int main() {
     cout << "Celsius Temperature Table\n\n";
     for(int i = 0; i <= 20; i++){
       double c = celsius(i);
       cout << i << "f is " << c << "c\n";
     }
     return 0;
   }

Aucun commentaire:

Enregistrer un commentaire