Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming Language C++ I need help, if i put 1 ft 2 inch i convert to 14 inch then multiply by 2.54 My ouput returns

Programming Language C++

I need help, if i put

1 ft 2 inch

i convert to 14 inch then multiply by 2.54

My ouput returns 0.0,

I bolded, where the changes need to happen to make this work. Not sure if i have those correct or not.

TCHAR * ConvertToCentimeters::Convert(TCHAR * szInput) { double feet = 1.0; // converted return value double inches = 0.0; double tInches; double centi;

feet = Parse(szInput); // parse user input

(tInches = (feet * 12) + inches); centi = tInches * 2.54; // copy value to output TCHAR _stprintf_s(szReturn, TEXT("%.*f"), 2, centi); // display output

return szReturn; ; }

double ConvertToCentimeters::Parse(TCHAR * szInput) { double feet = 0.0; // parsed value from user input double inches = 0.0; // parsed value from user input double tInches = 0.0; double centi = tInches; string strInput; // user input converted to string string strWork; // parsed input size_t pReturnValue; // return value for msbstows_s()

try { if (lstrlen(szInput) == 0) // don't allow 0 length input throw 0;

// convert to upper case for (int i = 0; i < lstrlen(szInput); i++) szInput[i] = _totupper(szInput[i]);

// convert TCHAR To String wstring temp(szInput); string str(temp.begin(), temp.end()); strInput = str;

// get feet int f = strInput.find("F"); // finds the letter f if (f == string::npos) // if no f in string throw badChars(); // throw expecption

strWork = strInput.substr(0, f); // grabs all chars up to letter g

// convert work to TCHAR mbstowcs_s( &pReturnValue, szReturn, 100, strWork.c_str(), 100);

// convert work string to double feet = _tstof(szReturn);

// get oz int i = strInput.find("I"); if (i != string::npos) // convert if ther is an i { while (strInput.at(f + 1) != ' ') f++;

strWork = strInput.substr(f + 1, 0 - (f + 1)); // grab chars after feet to get i

// convert work to TCHAR mbstowcs_s( &pReturnValue, szReturn, 100, strWork.c_str(), 100);

// convert work to double string inches = _tstof(szReturn); if (inches >= 12.0) throw tooManyInches(); } return centi; } catch (int) { MessageBox(NULL, TEXT("Invalid Entry"), TEXT("Exception"), NULL); return 0.00; } catch (badChars) { MessageBox(NULL, TEXT("Missing Feet or Inches Indicator"), TEXT("Exception"), NULL); return 0.00; } catch (tooManyInches) { MessageBox(NULL, TEXT("Inches must be equal to 12 or less"), TEXT("Exception"), NULL); return 0.00; } }

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

AutoCAD Database Connectivity

Authors: Scott McFarlane

1st Edition

0766816400, 978-0766816404

More Books

Students also viewed these Databases questions

Question

LO2 Compare three types of individual incentives.

Answered: 1 week ago