Question: I can't get my C + + code to do input validation on all values entered and I need it to . I need it

I can't get my C++ code to do input validation on all values entered and I need it to. I need it to reject a negative input for all entered.
#include
using namespace std;
int getArea(){
int area;
do {
cout << "Enter the square feet of floor space in the room: ";
cin >> area;
if (area <0){
cout << "Invalid input. Please enter a non-negative value.
";
}
} while (area <0);
return area;
}
int main(){
int numRooms, areaPerRoom, totalArea =0;
double carpetPricePerSqFt, totalCost, laborCost;
cout << "Enter the number of rooms to be carpeted: ";
cin >> numRooms;
for (int i =1; i <= numRooms; ++i){
cout << "Room "<< i <<":
";
areaPerRoom = getArea();
totalArea += areaPerRoom;
}
cout << "Enter the price of the carpet per square foot: $";
cin >> carpetPricePerSqFt;
// Calculate labor cost
int laborHours = totalArea /50;
laborCost = laborHours *6*30;
// Calculate total cost
double carpetCost = totalArea * carpetPricePerSqFt;
totalCost = carpetCost + laborCost;
// Display the results
cout <<"
Area to be carpeted: "<< totalArea <<" square feet" << endl;
cout << "Cost of the carpet: $"<< carpetCost << endl;
cout << "Cost of labor: $"<< laborCost << endl;
cout << "Total cost to the customer: $"<< totalCost << endl;
return 0;
}

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!