Question: MSC 1 1 0 : Computer Programming 2 home > 3 . 1 6 : Application: Input Validation zyBooks catalog ( c ) jeanma 8

MSC 110: Computer Programming 2 home >3.16 : Application: Input Validation
zyBooks catalog
(c) jeanma85/iStockphoto.
Suppose you are charged with writing a program that processes rat weights. We don't know for sure how giant a rat could be, but the New Guinea rats weighed no more than 2kg. A regular house rat (Rattus rattus) weighs up to 0.2kg, so we'll say that any weight >10kg was surely an input error, perhaps confusing grams and kilograms. Of course, inputs should be positive numbers. Rearrange the following lines of code to supply error handling. Not all lines are useful.
How to use this tool
Unused
else if (weight 0)
{
cout "Error: Weight must be positive" endl;
}
if (!cin.fail())
else if (cin.fail())
if (cin.fail())
else
{
{
cout "Error: Not a number" endl;
}
}
else if (weight >10)
{
else if (weight 0)
int main()
{
cout "Enter weight in kg : " end l;
double weight;
cin weight;
}
#include kg
 MSC 110: Computer Programming 2 home >3.16 : Application: Input Validation

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!