Question: C++ // Project Description:Unit Conversion Tables; This program will convert a variety of differnt units to the desired unit of measurment. // Inputs:dimensions, starting and
C++
// Project Description:Unit Conversion Tables; This program will convert a variety of differnt units to the desired unit of measurment.
// Inputs:dimensions, starting and ending units/values, # of digits after starting/ending units, increments
// Outputs:A table with the desired variables and values.
//*************************************************************
#include
#include
#include
using namespace std; //introduces namespace std
void TCCLogo ();// Displays TCC logo on printout screen
string StringToLower(string); // will convert input unit to lowercase letter.
double DimensionConvert(string,string,string,double,double&); // Function for converting dimension of length (m,ft,cm,in), Mass (kg,g,slug), and Time (h,min,s)
string findTheAbbrrivtn(string inUnit); //Function to return the abbreviated unit
string CaseConvert(string inputUnit); //function to convert inputed units to their full name (lowercased)
int main ( void )
{
TCCLogo (); // CALL FUNCTION
char Rerun ='y';
double s_values,end_values,increments,i, e_values,convert;
int unitValue, s_dp,e_dp,Dim;
string inputUnit;
string InputString, Lower;
string DimVal,s_units,e_units;
do // should allow the user to re-run the program if they wish to
{
cout<<"This program will convert units of length, mass, and time from one specified unit to another."< do //do while structure allows the user to re-enter invalid data such as length, mass and time ---> This Do While structure repeats an adidional time when I re-run the program... Whats with that? How do I stop that? { cout<<"What dimension would you like to convert in? 1) Length 2) Mass 3) Time "< getline (cin, DimVal); // stating dimension to be converted DimVal = StringToLower(DimVal); // CALL FUNCTION (Will convert input unit to lowercase letter) DimVal= CaseConvert(DimVal); //CALL FUNCTION (function to convert inputed units to their full name) if(DimVal =="invalid") { cout<<"Error. Invalid dimension. Please re-enter data."< cout<<"Be sure to check if your spelling is correct."< } }while (DimVal =="invalid"); if(DimVal == "length")// if else structure assigns demensions to int varables to be used in my switch/case structure { Dim = 1; } else if(DimVal == "mass") { Dim = 2; } else if(DimVal == "time") { Dim = 3; } do { switch (Dim) { case 1: { cout<<"What are your starting units? Meter, Foot, Centimeter or Inch? "< getline (cin, s_units); // starting unit to be converted... s_units= StringToLower(s_units); // CALL FUNCTION (Will convert input unit to lowercase letter) s_units= CaseConvert(s_units); //CALL FUNCTION (function to convert inputed units to their full name) cout<<"What are your ending units? Meter, Foot, Centimeter or Inch?"< getline (cin,e_units); // ending unit to be converted... e_units= StringToLower(e_units); // CALL FUNCTION (Will convert input unit to lowercase letter) e_units= CaseConvert(e_units); //CALL FUNCTION (function to convert inputed units to their full name) if(s_units=="invalid" || e_units =="invalid") { cout<<"Error. Invalid input. Please re-enter units."< cout<<"Be sure to check if your spelling is correct."< cout<<"Starting units cannot match ending units."< } } break; case 2: { cout<<"What are your starting units? Kilogram, Gram or Slug? "< getline (cin, s_units); // starting unit to be converted... s_units= StringToLower(s_units); // CALL FUNCTION (Will convert input unit to lowercase letter) s_units= CaseConvert(s_units); //CALL FUNCTION (function to convert inputed units to their full name) cout<<"What are your ending units? Kilogram, Gram or Slug? "< getline (cin,e_units); // ending unit to be converted... e_units= StringToLower(e_units); // CALL FUNCTION (Will convert input unit to lowercase letter) e_units= CaseConvert(e_units); //CALL FUNCTION (function to convert inputed units to their full name) if(s_units=="invalid" || e_units =="invalid") { cout<<"Error. Invalid input. Please re-enter units."< cout<<"Be sure to check if your spelling is correct."< cout<<"Starting units cannot match ending units."< } } break; case 3: { cout<<"What are your starting units? Hour, Minute or Second? "< getline (cin, s_units); // starting unit to be converted... s_units= StringToLower(s_units); // CALL FUNCTION (Will convert input unit to lowercase letter) s_units= CaseConvert(s_units); //CALL FUNCTION (function to convert inputed units to their full name) cout<<"What are your ending units? Hour, Minute or Second? "< getline (cin,e_units); // ending unit to be converted... e_units= StringToLower(e_units); // CALL FUNCTION (Will convert input unit to lowercase letter) e_units= CaseConvert(e_units); //CALL FUNCTION (function to convert inputed units to their full name) if(s_units=="invalid" || e_units =="invalid") { cout<<"Error. Invalid input. Please re-enter units."< cout<<"Be sure to check if your spelling is correct."< cout<<"Starting units cannot match ending units."< } } break; default: cout<<"Invalid entry. Please re-enter data."< } }while (s_units=="invalid"||e_units=="invalid"); do // Will calculate how many line there are in the table, will display error message if less than 3 or more than 25. { do //do while structure allows the user to re-enter invalid starting/ending units and incriments, that are negatie numbers. { cout<<"What are your starting values?"< cin>> s_values; //starting values cout<<"What are your ending values?"< cin>> end_values; //ending values cout<<"What are the increments?"< cin>> increments; // displays error message if negative numbers have been inputed for starting/ending values as well as increments. Prompts user to re-enter data. if(s_values<0 || end_values<0 || increments<0) { cout<<"Error. Starting value, ending value, and increment must all be positive."< cout<<"Please re-enter data."< } }while (s_values<0 || end_values<0 increments<0);> double count=0; for ( s_values; s_values<=end_values; s_values+=increments ) //displays my table of final results { convert = DimensionConvert(DimVal,s_units,e_units,s_values,e_values); // CALL FUNCTION. Function where my return values are calculated. // cout< count++; //s_values+=increments; // not sure why,but I feel like I will need this... } if(count>=3 || count<=25) { cout<<"Error, invalid data. Table is less than 3 or more than 25 lines. "< } }while (count>=3 || count<=25); do //do while structure alows user to re-enter invalid data if number of digits after decimal point are less than zero (negative number) { cout<<"What are the number of digits after the decimal point for the starting unit?"< cin>> s_dp; //starting # of digits after decimal point cout<<"What are the number of digits after the decimal point for the ending unit?"< cin>> e_dp; //ending # of digits after decimal point // displays error message if negative numbers have been inputed. Prompts user to re-enter data. if(s_dp<0 ||e_dp<0) { cout<<"Error. Number of digits must be greater than or equal to zero."< cout<<"Please re-enter data."< } }while(s_dp<0 ||e_dp<0);> // This code displays the table on page 3 of the project worksheet. It is totally optional, for now im using it for troubleshooting. cout<<" "< setw(12)<<"Increment"< cout< < s_units = findTheAbbrrivtn(s_units); //Function to return the abbreviated unit --->these work e_units = findTheAbbrrivtn(e_units); //Function to return the abbreviated unit --->these work cout<<" "< for ( s_values; s_values<=end_values; s_values+=increments ) //displays my table of final results { convert = DimensionConvert(DimVal,s_units,e_units,s_values,e_values); // CALL FUNCTION. Function where my return values are calculated. cout< } cout<<" "<<"Would you like to re-run the program? (Yes or No): "; cin>> Rerun; }while (Rerun =='y'|| Rerun == 'Y'); // this is the do while statement that repeats an additional time, for some reason. return 0; } Please help!! When I chose to re-run the program the initial question repeats twice for some reason. I'm not sure why my code wont calculate the number of lines in my table (must be greater than equal to 3 and less than equal to 25).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
