Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help! I have no idea why my code doesn't work. #include #include #include #include // declare transform into scope (transform(inputUnit.begin(), inputUnit.end(), inputUnit.begin(), ::tolower);) using

image text in transcribed

image text in transcribed

image text in transcribed

Please help! I have no idea why my code doesn't work.

#include

#include

#include

#include // declare transform into scope (transform(inputUnit.begin(), inputUnit.end(), inputUnit.begin(), ::tolower);)

using namespace std; //introduces namespace std

void TCCLogo ();

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

//Function to display the table

//void printTheTable(string s_units, string e_unit, double s_value, double e_value, double increment, int s_dp, int e_dp);// Pretty sure I dont need this one...

string LowerCaseConvert(string inputUnit); //function to convert to lower case unit

int main ( void )

{

char Rerun='y',choice,length,mass,time;

// CALL FUNCTION

TCCLogo ();

double s_values,end_values,increments,i, e_values,convert;

int unitValue, s_dp,e_dp;

// int feet,meters,inches,centimeters,minutes,hours,seconds,kilograms,grams,slugs;

string InputString, Lower;

//InputString = D; // its reading only D as a string, but I need it to be able to read my units as strings as well...

string DimVal,s_units,e_units;

do // should allow the user to re-run the program if they wish to

{

//LowerCaseConvert(DimVal); //function to convert to lower case unit

cout

do

{

cout

//cin>>DimVal;

//cin.clear();

// cin.ignore(100,' ');

//

getline (cin, DimVal); // stating dimension to be converted...

DimVal = StringToLower(DimVal); // CALL FUNCTION (Will convert input unit to lowercase letter)

}while (DimVal =="invalid");

do

{

cout

//cin>>s_units;

// I have no idea why The program skips the other inputs after I enter my dimension!?

// starting units

getline (cin, s_units); // starting unit to be converted...

s_units= StringToLower(s_units); // CALL FUNCTION (Will convert input unit to lowercase letter)

cout

//cin>>end_units //ending units

getline (cin,e_units); // ending unit to be converted...

e_units= StringToLower(e_units); // CALL FUNCTION (Will convert input unit to lowercase letter)

}while (s_units!= s_units);

cout

cin>> s_values; //starting values

cout

cin>> end_values; //ending values

cout

cin>> increments;

cout

cin>> s_dp; //starting # of digits after decimal point

cout

cin>> e_dp; //ending # of digits after decimal point

string LowerCaseConvert(string s_unit); //function to convert to lower case unit

string findTheAbbrrivtn(string inUnit); //Function to return the abbreviated unit

// 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)

cout

convert = DimensionConvert(DimVal,s_units,e_units,s_values,e_values); // CALL FUNCTION, my code works up untill here, something goes wrong that prevents my final table from being displayed...

cout

for ( s_values; s_values

{

//convert = DimensionConvert(DimVal,s_units,e_units,s_values); // CALL FUNCTION, my code works up untill here, something goes wrong that prevents my final table from being displayed...

double temp= (s_values*e_values);

cout

//s_values+=increments;

}

cout

cin>> Rerun;

}while (Rerun =='y'|| Rerun == 'Y');

return 0;

}

// Function Definition

void TCCLogo () //displays TCC logo

{

cout

cout

cout

cout

cout

}

string StringToLower(string strToConvert) //change each element of the string to lower case

{

for(unsigned int i=0; i

{

strToConvert[i] = tolower(strToConvert[i]);

}

return strToConvert; // return the converted string

}

// Function for converting dimension of length (m,ft,cm,in), Mass (kg,g,slug), and Time (h,min,s)... 188 lines of code

double DimensionConvert(string DimVal,string s_units,string e_units,double s_values,double e_values)

{

//find the unit abbrivations

//string abrStartUnit=findTheAbbrrivtn(s_units), abrEndUnit=findTheAbbrrivtn(e_units);

//double e_values,s_values;

int Dim ;

int unitValue;

//double e_values;

if(DimVal == "length")

{

Dim = 1;

}

else if(DimVal == "mass")

{

Dim = 2;

}

else if(DimVal == "time")

{

Dim = 3;

}

//cout

switch (Dim)

{

case 1: //test case for dimention length; units feet to meter, cm or inch

{

// int unitValue;

switch (unitValue)

{

if(s_units == "meters")

{

unitValue = 1;

}

else if(s_units == "centimeters")

{

unitValue = 2;

}

else if(s_units == "feet")

{

unitValue = 3;

}

else if(s_units == "inches")

{

unitValue = 4;

}

//cout

//int "meters"=1,"centimeters"=2,"feet"=3,"inches"=4;

case 1: // starting unit is meter

{

if(s_units == "meters"&& e_units =="feet")

{

e_values = s_values/3.28084;

//return e_values;

}

else if (s_units=="meters" && e_units=="centimeters")

{

e_values = s_values*100;

//return e_values;

}

if (s_units=="meters" && e_units=="inches")

{

e_values = s_values*39.37;

//return e_values;

}

}

break;

case 2: //starting unit is cm

{

if (s_units=="centimeters" && e_units=="meters")

{

e_values = s_values/100;

}

else if (s_units=="centimeters" && e_units=="inches")

{

e_values = s_values/2.54;

}

else if (s_units=="centimeters" && e_units=="feet")

{

e_values = s_values/30.48;

// return e_values;

}

}

break;

case 3://starting unit is ft

{

if (s_units=="feet" && e_units=="meters") // The way I wanted to do it... 119 lines of code

{

e_values = .3048;

//cout

//return e_values; // Can't get the e_values to return... So now I can't do any calculations!...

}

else if (s_units=="feet" && e_units=="centimeters")

{

e_values =30.48;

//return e_values;

}

else if (s_units=="feet" && e_units=="inches")

{

e_values=12;

//return e_values;

}

}

break;

case 4://starting unit is in

{

if (s_units=="inches" && e_units=="meters")

{

e_values = s_values/39.37;

//return e_values;

}

else if (s_units=="inches" && e_units=="feet")

{

e_values = s_values/12;

//return e_values;

}

else if (s_units=="inches" && e_units=="centimeters")

{

e_values = s_values*2.54;

//return e_values;

}

}

break;

}

}

case 2:// test case for dimension mass

{

if(s_units == "kilograms")

{

unitValue = 1;

}

else if(s_units == "grams")

{

unitValue = 2;

}

else if(s_units == "slugs")

{

unitValue = 3;

}

//int unitVal;

switch (unitValue)

{

case 1:// starting unit is kg

{

if (s_units=="kilograms" && e_units=="grams")

{

e_values=s_values*1000;

//return e_values;

}

else if (s_units=="kilograms" && e_units=="slugs")

{

e_values=s_values*.0685218;

//return e_values;

}

}

break;

case 2://starting unit is grams

{

if (s_units=="grams" && e_units=="slugs")

{

e_values=s_values*6.85522e-5;

//return e_values;

}

else if (s_units=="grams" && e_units=="kilograms")

{

e_values=s_values*.001;

//return e_values;

}

}

break;

case 3://starting unit is slugs

{

if (s_units=="slugs" && e_units=="kilograms")

{

e_values=s_values*14.5939;

//return e_values;

}

else if (s_units=="slugs" && e_units=="grams")

{

e_values=s_values*14593.9;

//return e_values;

}

}

break;

}

}

case 3://test case for dimension time

{

//int unitVal;

switch(unitValue)

{

if(s_units == "kilograms")

{

unitValue = 1;

}

else if(s_units == "grams")

{

unitValue = 2;

}

else if(s_units == "slugs")

{

unitValue = 3;

}

case 1://starting unit is hours

{

if (s_units=="hours" && e_units=="minutes")

{

e_values=s_values*60;

//return e_values;

}

else if (s_units=="hours" && e_units=="seconds")

{

e_values=s_values*3600;

//return e_values;

}

}

break;

case 2://starting unit is min

{

if (s_units=="minutes" && e_units=="hours")

{

e_values=s_values*.0166667;

//return e_values;

}

else if (s_units=="minutes" && e_units=="seconds")

{

e_values=s_values*60;

//return e_values;

}

}

break;

case 3://starting unit is sec

{

if (s_units=="seconds" && e_units=="minutes")

{

e_values=s_values*.0166667;

//return e_values;

}

else if (s_units=="seconds" && e_units=="hours")

{

e_values=s_values*.000277778;

//return e_values;

}

}

break;

//

}

}

return e_values;

// default:

//cout

}

}

// Probably dont even need this one, but if I do here it is... 59 lines of code string LowerCaseConvert(string inputUnit) //function to convert to lower case unit { transform(inputUnit.begin(), inputUnit.end(), inputUnit.begin(), ::tolower); // This is nice, but I already have a function to convert to lowercase. Do I still need to specify "tolower"? if(inputUnit== "m" || inputUnit == "meter" || inputUnit == "meters"){

return "meter";

}else if(inputUnit == "ft" || inputUnit == "feet" || inputUnit=="feets"){

return "feet";

}else if(inputUnit == "centimeter" | inputUnit == "cm" || inputUnit == "centimeters"){

return "centimeter";

}else if(inputUnit == "inch" || inputUnit == "in" || inputUnit == "inches"){

return "inch";

}else if(inputUnit == "hour" || inputUnit == "hours" || inputUnit =="h"){

return "hour";

}else if(inputUnit == "m" || inputUnit =="minute" || inputUnit == "minutes"){

return "minute";

}else if(inputUnit == "s" || inputUnit == "second" ||inputUnit =="seconds"){

return "second";

}else if(inputUnit == "kg" || inputUnit =="kilogram" || inputUnit =="kilograms"){

return "kilogram";

}else if(inputUnit == "gram" || inputUnit =="g" || inputUnit =="grams"){

return "gram";

}else if(inputUnit =="slug" || inputUnit =="slugs"){

return "slug";

}else if(inputUnit =="length" ||inputUnit =="lengths"){

return "length";

}else if(inputUnit =="mass"){

return "mass";

}else if(inputUnit =="time" || inputUnit =="times"){

return "time";

} return "invalid"; }

ter Introduction to Engineering Methods (C++) File: N125P2F Programming Assignment #2: Unit('onversion Tables This programming project will allow the user to create a table of unit conversions, where the user specifies . the dimension (example: length) the starting unit (example: ft) . ending unit (example: m) e the starting value (example: 0) e the ending value (example: 10) e the increment (1) e the number of digits after the decimal point for the starting unit (example: 1) . the number of digits after the decimal point for the ending unit (example: 3) he For the example above, the output might be similar to the table shown below: 39 Length (ft) 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 Length (m) 0.000 0.305 0.610 0.914 1.219 1.524 1.829 2.134 2.438 2.743 3.048 Program Requirements: I. The program should provide an initial description. 2. The user should be prompted to enter the dimension (length, mass, or time). 3. The user should be given a choice of initial units and final units for each dimension as follows: t.r , . Length: m, ft, cm or in t1k Note that the initial unit cannot be the same as the final unit, but there are still many possible conversions. For example, with length there are 12 possible conversions m to ft f tom em to m in to m m to cmft to em d cm to ft in to ft m to in ft to in cm to in in to cm Similarly, there are multiple conversion possibilities for mass and time

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Python Programming MySQL MongoDB OOP And Tkinter

Authors: R. PANNEERSELVAM

1st Edition

9357011331, 978-9357011334

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago