My code is lengthy due to the program description.
Code:
//Chris Taylor
//March 15th, 2006
//Intermediate C++, Terminal 6.
//Cube Thingy
#include <iostream.h>
#include <fstream.h>
#include <conio.h>
//Prototype dstatements
void pdescription();
int choice (int choose);
float c(float fa);
float f(float ce);
void output(float fa, float ce);
int main()
{
//Variable declaration
float fa; //Fahrenheit variable.
float ce; //Celsius variable.
int choose=0; //Stored for intial choice.
pdescription();//Calls the function "description"
choice (choose);//Calls the function "choice"
if (choose==0)//Determines what is being converted to what.
{
f(ce);
}
else
{
c(fa);
}
output(fa, ce);
getch();
return 0;
}
void pdescription()//Prints out program description
{
cout << "This program will print out two random value for triangle legs, determine the hypotenuse, and quiz the user on the answer.\n";
}
int choice(int choose)//Allows user to choose what is being converted to.
{
cout << " 0. Fahrenheit\n";
cout << " 1. Celsius\n";
cin >> choose;
return choose;
}
float c(float fa)//For converting into fahrenheit.
{
float ce=0;
cout << "Input your celsius vaulue and press\nENTER.\n";
cin >> ce;
fa=(1.8*ce)+32; //Formula to convert c to f.
return fa;
}
float f(float ce)//For converting into celsius.
{
float fa=32;
cout << "Input your fahrenheit vaulue and press\nENTER.\n";
cin >> fa;
ce=(fa-32)*(5.0/9.0);//Formula to convert f to c.
return ce;
}
void output(float fa, float ce)//Prints fahrenheit and celsius value to the screen.
{
clrscr();
cout << "Fahrenheit value is: " << fa << endl;
cout << "Celsius value is: " << ce;
}