Write a program that convert integer Fahrenheit temperature to Celsius or Celsiu
ID: 3699049 • Letter: W
Question
Write a program that convert integer Fahrenheit temperature to Celsius or Celsius to Fahrenheit. Use floating points with 3-digit precision. Your program should 1- Prompt to CF or FC. Where CF converting Celsius to Fahrenheit and FC to convert for converting from Fahrenheit to Celsius. 2- Once you are ready to enter CF or FC, then a. Enter FC and then enter 5 testing values all at once and hit enter to give the final answers in two colmuns – Column 1: Your entered values and Column 2: Your converted value. b. Repeat step a for CF
Explanation / Answer
ANSWER :
TempConverter.c
#include<stdio.h>
int main()
{
float cel,fah;
float arr1[5],arr2[5]; //array to save user input and CF or FC value
int ch,i;
printf("Choose option : ");
printf("1. CF ");
printf("2. FC ");
printf("Option : ");
scanf("%d",&ch); //select option CF or FC
switch(ch)
{
case 1:
printf("Enter 5 Celcius values to convert into Fahrenheit: ");
for(i=0;i<5;i++) //loop to take user input in Celcius
{
printf("Test value %d : ",i+1);
scanf("%f",&arr1[i]);
arr2[i] = arr1[i]*1.8 + 32; //convert celcius into fahrenheit
}
printf(" %10s%20s","Celcius","Fahrenheit");
printf(" ---------------------------------------");
for(i=0;i<5;i++) //print result in C to F
{
printf(" %10.3f%20.3f",arr1[i],arr2[i]);
}
break;
case 2:
printf("Enter 5 Farenheit values to convert into Celcius: ");
for(i=0;i<5;i++) //loop to take user input in Fahrenheit
{
printf("Test value %d : ",i+1);
scanf("%f",&arr1[i]);
arr2[i] = (arr1[i]-32)*5/9; //convert fahrenheit into celcius
}
printf(" %10s%20s","Fahrenheit","Celcius");
printf(" ----------------------------------------");
for(i=0;i<5;i++) //print result in F to C
{
printf(" %10.3f%20.3f",arr1[i],arr2[i]);
}
break;
default:
printf("Wrong choice :");
break;
}
}
OUTPUT :
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.