I think I asked this before, but can't find it in my posts. Feel like an idiot asking it again.
Anyways there are two if()'s. The first one is to convert degrees F to C through a function. I have already done it without functions as shown in the second if().
The problem is that the function keeps sending tempF to be 0...it seems. Tried reading it out loud what it does but the program makes sense in my head. Here is the code:
Code:
#include <stdio.h>
#include <stdlib.h>
float tempC;
float tempF;
float calcCelsius1(tempF);
int main()
{
int choice;
float start_temp;
float end_temp;
float temp_incr;
printf("Which Temperature Scale Conversion would you like to perform?\n");
printf("1. Convert F to C\n2. Convert C to F\n\n");
printf("What is your choice? ");
scanf("%d", &choice);
if (choice == 1)
{
printf("\nStarting Temperature: ");
scanf("%f", &start_temp);
printf("Ending Temperature: ");
scanf("%f", &end_temp);
printf("Temperature Increment: ");
scanf("%f", &temp_incr);
tempF = start_temp;
printf("\n\nFahrenheit\t\tCelsius\n");
printf("----------\t\t-------\n");
while(tempF<end_temp)
{
tempC = calcCelsius1(tempF);
printf("TempC = %f\n", tempC);
printf("%6.1f\t\t\t%6.1f\n", tempF, tempC);
tempF = tempF + temp_incr;
}
tempF = end_temp;
tempC = calcCelsius1(tempF);
printf("%6.1f\t\t\t%6.1f\n", tempF, tempC);
}
else if (choice == 2)
{
printf("\nStarting Temperature: ");
scanf("%f", &start_temp);
printf("Ending Temperature: ");
scanf("%f", &end_temp);
printf("Temperature Increment: ");
scanf("%f", &temp_incr);
tempC = start_temp;
printf("\n\nCelsius\t\t\tFahrenheit\n");
printf("-------\t\t\t----------\n");
while(tempC<end_temp)
{
tempF = tempC*9/5 + 32;
printf("%6.1f\t\t\t%6.1f\n", tempC, tempF);
tempC = tempC + temp_incr;
}
tempC = end_temp;
tempF = tempC*9/5 + 32;
printf("%6.1f\t\t\t%6.1f\n", tempC, tempF);
}
else
printf("Not a valid choice.\n");
return 0;
}
float calcCelsius1 (tempF)
{
tempC = (tempF - 32)*5/9;
return tempC;
}
I finally got to fit a C++ class in my schedule for spring. So hopefully formal education on the subject will stop me coming here (asking questions that is)