0

About a code.

How would I validate the input of the length width and area to be greater than 0. Using just if/ if else statements. My output is still allowing 0 and I dont want that. if (choose < 1 || choose > 4) { cout << "Invalid value..Please enter again.\n"; } else if (choose == SQUAREROOM) { cout << "Enter the width of the room.\n"; cin >> width; area = width*width; cout << "The width of the squareroom is \n" << area << endl; } else if (choose == RECTANGULARROOM) { cout << "Enter the length and width of the room.\n"; cin >> length >> width; area = length*width; cout << "The area of the rectangular room is \n." << area << endl; } else if (choose == ROUNDROOM ) { cout << "Enter the radius of the room.\n"; cin >> radius; area = PI*radius*radius; cout << "The area of the roundroom is \n" << area << endl; } else if (choose == QUIT ) { cout << "Thank you for using Haverly's Calculator. \n"; } return 0; }

1st Nov 2018, 5:36 AM
K.D
K.D - avatar
1 Odpowiedź
+ 8
You are not validating any user input for width or height at all. Use an if statement.
1st Nov 2018, 6:14 AM
jay
jay - avatar