Question
I keep getting a crazy number and I know it's not right. can you please help me?
Write a C++ program which reads in Fahrenheit tenperatures (type float their from the keyboard and can them centigrade equivalents; recall the rule Centigrade 5.0/9.0) (Fahrenheit 32) converting Fahrenheit to centigrade for should our progran output both the inputted Fahrenheit tenpe and their Centigrade equivalents (See below When the input has been exhausted our program should also output the of the temperatures processed in both Fahrenheit and Centigrade Your progran should See the i llustration bel contain a read loop for reading in ane temperature at a time converting inputted that temperature outputting the and its Centigrade equivalent. and doing whatever temperature bookkeeping is needed for the computation before looping average back to input the next temperature Your program should be able to handle arbitrary number of input tenperatures The illustration below shows an input of seven temperatures Given the inputs 86.0 91.0 87.4 100.3 98.6 and 83.7 your program should output the following table: 77.0 fahrenheit centigrade B6.0 30.0 91.0 32.8 30.8 B7.4 100,3 37.9 98.6 37.0 77.0 25.0 83.7 28.7 89.1 31.7 average As usual, please hand in a paper copy of your c++ source code and a paper copy of your output Feel free to test your progran on any input of your choosing to help me in grading your work but Programning notes (a your tabular form fairly neat with column Try to make headings line skipping reasonable alignnent of nunber fields Print all n s to one decinal place for etc, accuracy consistency, When entering tenperatures at the keyboard you will of course, hit after each tenperature but how do you tell the enter computer that you are done entering data? hit the Ctr and z keys sinultaneously This signals EOF end-of-file to the aomputer (In UNIX, EOF is signalled by ctrl-D rather than ctrl-z
Explanation / Answer
#include <iostream>
#include<iomanip> // setprecision,setw and fixed manipulaor functions are defined here
using namespace std;
int main()
{
float tempfahrenheit,tempcentigrade,avgfahren,avgcenti;
avgfahren = avgcenti =0;
int count =0;
cout<<" Enter the temperature in fahrenheit";
cin>>tempfahrenheit; //input temperatures in fahrenheit
cout<<setprecision(1); //set manipulators
cout<<setw(20);
cout<<fixed;
cout<<" fahrenheit centigrade";
while( !cin.eof() ) //end loop with ctrl z
{
tempcentigrade = (5.0/9.0) * (tempfahrenheit -32); // unit conversion
cout<<" "<<tempfahrenheit<<" "<<tempcentigrade;
avgfahren = avgfahren + tempfahrenheit; //compute averages
avgcenti = avgcenti +tempcentigrade;
count++; //number of values entered
cin>>tempfahrenheit;
}
cout<<" average "<<avgfahren/count<<" "<<avgcenti/count;
return 0;
}
output: