Problem Description This program is to give the user the option of converting a
ID: 3550061 • Letter: P
Question
Problem Description
This program is to give the user the option of converting a set of temperatures either from Celsius to Fahrenheit (C to F) or vice versa, from Fahrenheit to Celsius (F to C), or to quit the program. If the user selects either C to F or F to C, the program will prompt the user to enter three integer values, a starting temperature, an ending temperature, and an increment. After these values have been entered the program will display a table of equivalent C and F (or F and C) temperatures, from the starting temperature to the ending temperature and incrementing by the increment value each row.
The table must meet all of the following criteria:
The formula to convert Celsius to Fahrenheit is
The formula to convert Fahrenheit to Celsius is
Function Requirements
You must create and use the following functions:
· displayMenu( ) displays a menu.
· getMenuSelection ( ) gets the menu selection from the user, upper or lower case 'C' for Celsius to Fahrenheit, upper or lower case 'F' for Fahrenheit to Celsius, and upper or lower case 'Q' to quit. Any other input should get an error message "Invalid selection: try again" and re-prompt for the menu selection.
· getStartEndAndIncrement( ) gets the start, end and increment values for the table from the user.
· CtoF( ) converts a Celsius temperature to Fahrenheit.
· FtoC( )converts a Fahrenheit temperatures to Celsius.
· displayTable( ) displays a C to F or F to C table given start, end and increment values and the conversion character the user selected.
Additional Requirements
· Absolutely NO GLOBAL VARIABLES can be used to implement this program! Any program using global variables will NOT be accepted!
·Use a switch statement to respond to the user's menu selection in the getMenuSelection function.
·After the user selects a valid temperature table option, ask the user to enter start, end, and increment values, then display the table and stop until the user presses the ENTER key to continue (prompt the user, of course). When the user presses ENTER to continue the menu should be redisplayed, allowing the user to make another menu selection (either to display another temperature conversion table or quit).
·Make sure that your code is properly formatted (indentation, etc) and that you have provided suitable documentation of all your functions (comment blocks for program and functions!).
How to print the degree symbol
It is easy enough to find out how to do this by searching the web. The short answer is:
cout << (char)248;
********************************************************************************************************************************************
I have most of this program written, I cannot seem to get my table to output in a correct alignment. Please help, I am so new to C++ programming!!!! If you could please make corrections within my source code as oppose to a completely new code I would greatly appreciate it!!!! Below is my code:
***************************************************************************************************
#include<iostream>
#include<iomanip>
using namespace std;
//Function prototypes
void displayMenu();
char getMenuSelection ();
void getStartEndAndIncrement( double &startTemp, double &endTemp, double &increment);
double FtoC(double F);
double CtoF(double C);
void displayTable(double startTemp, double endTemp, double increment,char choice );
int main()
{
double start, end, increment;
do
{
displayMenu();
char ch=getMenuSelection();
switch(ch)
{
case 'f':
case 'F':
getStartEndAndIncrement(start,end,increment);
cout<<" "<<setw(10)<<(char) 248 <<"F"<<setw(10)<<(char) 248<<"C"<<endl;
displayTable(start,end,increment,ch);
break;
case 'c':
case 'C':
getStartEndAndIncrement(start,end,increment);
cout<<" "<<setw(10)<<(char) 248 <<"C"<<setw(10)<<(char) 248<<"F"<<endl;
displayTable(start,end,increment,ch);
break;
case 'q':
case 'Q': return 0;
}
}while(1);
return 0;
}
void displayMenu( ) //Displays a menu
{
cout << "Choose one of the following slections: "
<< "'C' Will convert Celsius to Fahrenheit (C to F). "
<< "'F' Will convert Fahrenheit to Celsius (F to C). "
<< "'Q' Exit ";
return;
}
char getMenuSelection () //Gets choice from user
{
char choice;
cout << "Enter choice:";
cin >> choice;
return choice;
}
void getStartEndAndIncrement( double &startTemp, double &endTemp, double &increment) //Gets start, end, and increment from user.
{
cout << "Enter start temperature: ";
cin >> startTemp;
cout << "Enter end temperature: ";
cin >> endTemp;
do
{
cout << "Enter positive incremental value: ";
cin >> increment;
if(increment <= 0)
cout << "The increment value must be greater than 0. Please try again. ";
}while(increment <= 0);
return;
}
double CtoF(double C) //Converts a Celsius to Fahrenheit.
{
double F=(9.0/5.0)*C+ 32.0;
return F;
}
double FtoC(double F) //Converts a Fahrenheit to Celsius.
{
double C = (5.0/9.0)*(F-32.0);
return C;
}
void displayTable(double startTemp, double endTemp, double increment,char choice )
//displays a C to F or F to C table given start, end and increment values and the conversion character
//the user selected.
{
double i;
{
for(i=startTemp;i<=endTemp;i+=increment)
cout << setw(10) << i << (char) 248;
switch(choice)
{
case 'f':
case 'F':
cout << " " << setw(10) << FtoC(i) << (char) 248 << endl;
break;
case 'c':
case 'C':
cout << " " << setw(10) << CtoF(i) << (char) 248 << endl;
}
}
return;
}
Explanation / Answer
please rate - thanks
you were almost perfect
only changes are in display pages-
#include<iostream>
#include<iomanip>
using namespace std;
//Function prototypes
void displayMenu();
char getMenuSelection ();
void getStartEndAndIncrement( double &startTemp, double &endTemp, double &increment);
double FtoC(double F);
double CtoF(double C);
void displayTable(double startTemp, double endTemp, double increment,char choice );
int main()
{
double start, end, increment;
do
{
displayMenu();
char ch=getMenuSelection();
switch(ch)
{
case 'f':
case 'F':
getStartEndAndIncrement(start,end,increment);
cout<<" "<<setw(10)<<(char) 248 <<"F"<<setw(10)<<(char) 248<<"C"<<endl;
displayTable(start,end,increment,ch);
break;
case 'c':
case 'C':
getStartEndAndIncrement(start,end,increment);
cout<<" "<<setw(10)<<(char) 248 <<"C"<<setw(10)<<(char) 248<<"F"<<endl;
displayTable(start,end,increment,ch);
break;
case 'q':
case 'Q': return 0;
}
}while(1);
return 0;
}
void displayMenu( ) //Displays a menu
{
cout << "Choose one of the following slections: "
<< "'C' Will convert Celsius to Fahrenheit (C to F). "
<< "'F' Will convert Fahrenheit to Celsius (F to C). "
<< "'Q' Exit ";
return;
}
char getMenuSelection () //Gets choice from user
{
char choice;
cout << "Enter choice:";
cin >> choice;
return choice;
}
void getStartEndAndIncrement( double &startTemp, double &endTemp, double &increment) //Gets start, end, and increment from user.
{
cout << "Enter start temperature: ";
cin >> startTemp;
cout << "Enter end temperature: ";
cin >> endTemp;
do
{
cout << "Enter positive incremental value: ";
cin >> increment;
if(increment <= 0)
cout << "The increment value must be greater than 0. Please try again. ";
}while(increment <= 0);
return;
}
double CtoF(double C) //Converts a Celsius to Fahrenheit.
{
double F=(9.0/5.0)*C+ 32.0;
return F;
}
double FtoC(double F) //Converts a Fahrenheit to Celsius.
{
double C = (5.0/9.0)*(F-32.0);
return C;
}
void displayTable(double startTemp, double endTemp, double increment,char choice )
//displays a C to F or F to C table given start, end and increment values and the conversion character
//the user selected.
{
double i;
for(i=startTemp;i<=endTemp;i+=increment)
{cout << setw(10) <<setprecision(1)<<fixed << i << (char) 248;
switch(choice)
{
case 'f':
case 'F':
cout << setw(10)<<setprecision(1)<<fixed << FtoC(i) << (char) 248 << endl;
break;
case 'c':
case 'C':
cout << setw(10)<<setprecision(1)<<fixed << CtoF(i) << (char) 248 << endl;
}
}
return;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.