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
cout "Invalid input. Please enter a nonnegative value.
;
while area ;
return area;
int main
int numRooms, areaPerRoom, totalArea ;
double carpetPricePerSqFt, totalCost, laborCost;
cout "Enter the number of rooms to be carpeted: ;
cin numRooms;
for int i ; 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 ;
laborCost laborHours ;
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 ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
