-6

my code is Below I want convert Fahrenheit to degree Celsius in the following code but i am getting error does anybody know how to tackle with this error ?

#include <stdio.h>
int main()
{
    int frnhet[]={0,20,40,60,80,100,120,140,160,180,200,220,240,260,280,300};
    double celcius;
    int i;
    for(i=0;i<16;i++)
        {
      celcius = ((float)(5/9) + (float)(frnhet-32));
        printf("celcius = %f",celcius);
       }
     return 0;
 }
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97

5 Answers5

0

Your error is here:

celcius = ((float)(5/9) + (float)(frnhet-32));

it must be frnhet[i] since frnhet is an array

celcius = ((float)(5 / 9) + (float)(frnhet[i] - 32));
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
0

You missed index to frnhet in code. Please refer following code -

#include <stdio.h>

    int main()
    {
        int frnhet[]={0,20,40,60,80,100,120,140,160,180,200,220,240,260,280,300};
        double celcius;
        int i;
        for(i=0;i<16;i++)
            {
          celcius = ((float)(5/9) + (float)(frnhet[i]-32));
            printf("celcius = %f",celcius);
           }
         return 0;
     }
Ganeshdip
  • 389
  • 2
  • 10
0

frnhet is an array and in the expression frnhet-32 it will convert to pointer to its first element. Change frnhet-32 to frnhet[i]-32.

celcius = (5.0/9 + frnhet[i]-32);
haccks
  • 104,019
  • 25
  • 176
  • 264
0

Please change line

celcius = ((float)(5/9) + (float)(frnhet-32));

To

celcius = ((float)(5/9) + (float)(frnhet[i]-32));

you missed the index to access frnht array

Vagish
  • 2,520
  • 19
  • 32
0
#include <stdio.h>
int main()
{
    int frnhet[]={0,20,40,60,80,100,120,140,160,180,200,220,240,260,280,300};
    double celcius;
    int i;
    for(i=0;i<16;i++)
        {
      celcius = ((float)(5/9) + (float)(frnhet[i]-32));
        printf("celcius = %f",celcius);
       }
     return 0;
 } 

In celcius = ((float)(5/9) + (float)(frnhet-32)); you are passing pointer where it is excepting float value. for passing value use celcius = ((float)(5/9) + (float)(frnhet[i]-32));

yajiv
  • 2,901
  • 2
  • 15
  • 25