here is the assignment. write a program that prompts the user to enter a length
ID: 3611579 • Letter: H
Question
here is the assignment. write a program that prompts the user to enter a length in feetand inches and ouputs the equivalent length in centemeters. if theuser enters a negative number or a nondigit number, throw andhandle an approproiate exception and prompt the user to enteranother set of numbers. thanks for your help here is the assignment. write a program that prompts the user to enter a length in feetand inches and ouputs the equivalent length in centemeters. if theuser enters a negative number or a nondigit number, throw andhandle an approproiate exception and prompt the user to enteranother set of numbers. thanks for your help thanks for your helpExplanation / Answer
double read_double(char*message)
{
double dnum;
do
{
cout << message;
cin >> dnum;
if (cin.fail())
{
cout << endl << "Enter anumber " << endl;
flush(cin);
}
else
{
break;
}
}
while (1);
return dnum;
}
int main()
{
do
{
choice = -1;
cout << endl;
cout << "Conversion of inches,feet to cetimeters"<< endl;
cout << endl;
cout << "1 - Convert inches and feet to centimeters"<< endl;
cout << "0 - Quit" << endl;
cout << endl;
cout << "Enter choice : ";
cin >> choice;
if (cin.fail())
{
cout << endl << "** Enter a number**" << endl;
flush(cin);
}
if (choice == 1)
{
int inputok;
do
{
inputok = 1;
foot = read_double("Enter length in feet: ");
inches = read_double("Enter inches as well: ");
cout<<endl;
try
{
if(inches < 0 || foot < 0)
throw -1;
}
catch (int error)
{
cout << "Negative foot/inches nor Alphabetic lettersnot accepted. Enter again."
<< endl << endl;
inputok = 0;
}
} while (inputok !=1);
centimeters = (foot * 30.48f) + (inches * 2.54f);
cout << foot << " foot and " << inches << "inches equals "
<< centimeters << " centimeters." << endl;
} //<- end if
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.