I am using C++ and im having trouble printing within my for loop to look like th
ID: 3750910 • Letter: I
Question
I am using C++ and im having trouble printing within my for loop to look like the table below.
1. (20 points) Write a C++ program to print atable that displays conversion from Fahrenheit to Kelvin. The desired table can be: Table: Conversion from Fahrenheit to Kelvin Fahrenheit Kelvin 50F 40F 30F -20F 10F OF 10F 20F 30F 40F 50F 227.59K 233.15K 238.71K 244.26K 249.82K 255.37K 260.93K 266.48K 272.04K 277.59K 283.15K You can change the sample values shown in the table. The equation below shows how to convert Fahrenheit to Kelvin: Kelvin (Fahrenheit +459.67)5/9 where Fahrenhe-459.67Explanation / Answer
UPDATED PROGRAM
#include<iostream>
#include<iomanip> // setw() and setprecision
using namespace std;
int main()
{
//Declare double variables
double fahrenheit;
double kelvin;
// display header
cout<<"Degrees in Fahrenheit converted to Kelvin:"<<endl;
cout<<" Fahrenheit"<<setw(20)<<"Kelvin"<<endl;
for(fahrenheit=-50;fahrenheit<=50;fahrenheit+=10) // create for loop until 50
{
kelvin=(fahrenheit+459.67)*5/9; // calculate kelvin
// display all temparature and kelvin in tabular format
cout<<fixed<<setprecision(0)<<fahrenheit<<"F"<<setw(27)<<fixed<<setprecision(2)<<kelvin<<"K"<<endl;
}
return 0;
}
OUTPUT
Degrees in Fahrenheit converted to Kelvin:
Fahrenheit Kelvin
-50F 227.59K
-40F 233.15K
-30F 238.71K
-20F 244.26K
-10F 249.82K
0F 255.37K
10F 260.93K
20F 266.48K
30F 272.04K
40F 277.59K
50F 283.15K
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.