Redo this exercise , but use C. Print a table of Fahrenheit and Celsius temperat
ID: 3548698 • Letter: R
Question
Redo this exercise , but use C.
Print a table of Fahrenheit and Celsius temperatures.
Let the user input the starting and ending fahrenheit temperatures.
Then print the table with centered column headings and field widths.
Also use a plus sign for the positive celsius temperatures, but not for the positive fahrenheit temperatures.
Use spaces for the field width in front of the fahrenheit, but instead of a dot leader in front of the celsius, use zeros to pad the field width.
\This program will print a temperature table
#include<iostream>
#include<iomanip>
using namespace std;
void main()
{
int fah, f1, f2;
float cel;
cout.setf(ios::showpoint|ios::fixed);
cout << "Enter starting fahrenheit: ";
cin >> f1;
cout << "Enter ending fahrenheit: ";
cin >> f2;
cout << "Fahrenheit" << setw(12) << "Celsius" << endl;
for (fah = f1; fah <= f2; fah++)
{
cel = (fah - 32) * 5 / 9.0;
cout << setw(6) << resetiosflags(ios::showpos) << setfill(' ') << fah
<< setw(16) << setiosflags(ios::showpos) << setfill('0')
<< setprecision(3) << cel << endl;
}
}
Explanation / Answer
#include<stdio.h>
int main()
{
int fah, f1, f2;
float cel;
printf("Enter starting fahrenheit: ");
scanf("%d",&f1);
printf("Enter ending fahrenheit: ");
scanf("%d",&f2);
printf("Fahrenheit Celsius ");
for (fah = f1; fah <= f2; fah++)
{
cel = (fah - 32) * 5 / 9.0;
printf(" %2.2d %3.3f",fah,cel);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.