I have an assignment where I find the cost of shipping an item based on input from a file. One section asks me to terminate the program when an "An invalid character is present in the text file"
Expected output:
*************** File Read Error ***************
==> Reading of one or more package
==> parameters failed!!
==> Terminating program!!!
***********************************************`
My output:
--------------------------------------------------
The package attributes are:
Package type .................bulk
Total length .................45 inches
Weight .......................2111390112 pound(s)
--------------------------------------------------
The package rate factors are:
Package Base Rate ............4.75 dollars
Length Factor Used ...........2.5
Weight Factor Used ...........4.5
--------------------------------------------------
Here is my Code:
if (typeid(length) != typeid(int) || typeid(width) != typeid(int) || typeid(height) != typeid(int) || typeid(weight) != typeid(int)) // tests the type of these variables
{
cout << string(15,'*') << " File Read Error " << string(15,'*') << endl;
cout << "==> Reading of one or more package" << endl;
cout << "==> parameters failed!!" << endl;
cout << "==> Terminating program!!!" << endl;
cout << string(47,'*') << endl << endl;
return 1;
}
Here is the text file:
// invalid character in height, width, length or weight
bulk
20
25
A15
25
Essentially, the program should terminate when it sees A15 because it has a char and expects just an integer.