I need to create a program that is a table to convert between centigrade and fahrenheit temperatures. My solution must must utilize functions to perform the conversions. Requirements:
1. One of the functions must use pass-by-value, returning the converted
measure
2. One of the functions must use pass-by-reference to store its result (the
function does not have a return value).
Program must create two tables - one showing the centigrade equivalent to
fahrenhrit measures from 0 degrees centigrade to 100 degrees centigrade (by 5
degree increments: 0, 5, 10, . . . , 100) and the other showing fahrenheit
equivalent to centigrade measures 0 through 100 (by 5 degree increments: 0, 5,
10, ... , 100). Original measures are all integer values. Calculated measures are to
be displayed accurate to two decimal places. The output for both tables must fit on
one default screen (78 columns by 22 rows), so your tables will need to be
organized into multiple columns. Everything must be lined up nicely and the tables
neatly and informatively labeled.
Well I got the program to line up correctly, but I want to see if the pass-by and pass values were correct. Can someone look at this and steer me correctly.
#include <iomanip>
using std::cout;
using std::endl;
using std::setw;
using std::fixed;
using std::setprecision;
int main()
{
float i=0;
float c= 0;
float &f= c;
cout << setw(25) << "Centigrade to Fahrenheit"
<< setw(35) << "Fahrenheit to Centigrade" << endl << endl;
cout << setw(6) << "Cent" << setw(18) << "Fahr"
<< setw(17) << "Fahr" << setw(19) << "Cent\n";;
for ( float i = 0; i <= 100; i+=5 )
{
float f = ((i * 9/5) + 32);
float c = ((i - 32)* 5/9);
cout << setw(6) << setprecision(0) << i << setw( 18 )
<< setprecision(2)<< fixed << f << setw(17)
<< setprecision(0) << i << setw(18)
<< setprecision(2) << c << endl;
}
return 0;
}
I also have a second version which I tried to use funsction but I get error after error. Can I get help with that one too?
#include <iostream>
#include <iomanip>
using std::cout;
using std::endl;
using std::setw;
using std::fixed;
using std::setprecision;
int centToFahr(float);
void centToFahr(float&);
int fahrToCent(float);
void fahrToCent(float&);
int main()
{
float i=0;
float c=0;
float f=0;
cout << setw(25) << "Centigrade to Fahrenheit"
<< setw(35) << "Fahrenheit to Centigrade" << endl << endl;
cout << setw(6) << "Cent" << setw(18) << "Fahr"
<< setw(17) << "Fahr" << setw(19) << "Cent\n";;
for ( float i = 0; i <= 100; i+=5 )
{
/*float f = ((i * 9/5) + 32);
float c = ((i - 32)* 5/9);*/
cout << setw(6) << setprecision(0) << i << setw( 18 )
<< setprecision(2)<< fixed << centToFahr(f) << setw(17)
<< setprecision(0) << i << setw(18)
<< setprecision(2) << fahrToCent(c) << endl;
}
return 0;
}
float centToFahr(float i, float f)
{
return f = ((i * 9/5) + 32);
}
float fahrToCent(float i, float c)
{
return c = ((i - 32)* 5/9);
}
Thank you,
M