I am learning C and need some help. The task is to use a while loop to output a table of Fahrenheit temperatures and their Celsius equivalents. I am going from 1 degree Fahrenheit (-17 Celsius) to 300 degrees Fahrenheit (148 Celsius) with increments of 20 degrees Fahrenheit. I want to output both temperatures with 2 decimal places (I am using %.2f). I am getting the following error:
22:33: warning: expression result unused
[-Wunused-value]
while ((i = upperbound), (i >= lowerbound), (i=i - increment))
~ ^ ~~~~~~~~~~
1 warning generated.
So lowerbound for some reason isn't being used. I have tried several things and none have worked. Please help! Here is the code:
#include <stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
int main()
{
double Tc=0;
double Tf=0;
double lowerbound = 1;
double upperbound = 15;
double increment = 1;
int i = 15;
while ((i = upperbound), (i >= lowerbound), (i=i - increment))
{
Tf=20*i;
Tc=((5.0*Tf)-(5.0*32.0))/9.0;
printf("%.2f\t%.2f\n", Tf, Tc);
}
printf("1.000000 %f\n",((5.0*1)-(5.0*32.0))/9.0);
return 0;
}
forloop withwhileloop and using,instead of;. - Shafik Yaghmour