23ts

closed account (3UMLy60M)
asdfhe45rt
Last edited on
You already have input validation in one place:
1
2
3
4
5
6
7
8
		cin >> choice;

		// Validate the menu selection
		while (choice < 1 || choice > 5)
		{
			cout << "Please select a valid choice of 1-5: ";
			cin >> choice;
		}
Just make something similar in each case.
you have to validate your numbers for each input.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
if (choice == 1)
		{
			// Get the length of the rectangle
			cout << "Please enter the length of a rectangle: ";
			cin >> rectangleLength;
			while (!(rectangleLength > 0))
			{
				cout << "Please select a positive number: ";
				cin >> rectangleLength;
			}

			// Get the width of the rectangle
			cout << "Please enter the width of a rectangle: ";
			cin >> rectangleWidth;
			while (!(rectangleWidth > 0))
			{
				cout << "Please select a positive number: ";
				cin >> rectangleWidth;
			}

			// Display the area of the rectangle
			area(rectangleLength, rectangleWidth);
		} 


Go through all you choices
Topic archived. No new replies allowed.