Create C++ Code for a program for Hansel\'s Housecleaning Service. The program p
ID: 3833889 • Letter: C
Question
Create C++ Code for a program for Hansel's Housecleaning Service.
The program prompts the user for a customer's last name only. While the last name is not “zzz” your program will ask for the number of bathrooms and the number of other rooms to be cleaned and display the cleaning charge. You should use a sentinel-controlled while loop in your main loop logic. A customer name of “zzz” signals the end of the data.
The cleaning charge is $40 plus $15 for each bathroom and $10 for each of the other rooms. Use data validation loop to make sure the number of bathrooms is >= 0, and the number of other rooms is also >= 0. The program will display the total cleaning charge and then prompt for the next customer's name.
When the loop is exited (user enters “zzz” for the last name), display a message indicating that the program is complete.
Your program will have the main module and a function that, given the number of bathrooms and the number of other rooms, will return that total cleaning charge for the customer.
This is the pseudocode I have
Begin module main
// Declare variables
Declare String name
Declare Real totalBill
Declare Integer NumBathrooms, numRooms
// Read the first name
Display “Enter last name or ‘zzz’ when done: “
Input name
// Continue to process while the name is not “ZZZZ”
While name != “ZZZZ”
// Read the number of bathrooms
Display “Enter number of bathrooms “
Input numBathrooms
// Check for invalid input
While numBathrooms < 0
Display “Invalid input – number of bathrooms cannot be negative
// Read the number of bathrooms again
Display “Re-enter number of bathrooms “
Input numBathrooms
// Read the number of other rooms
Display “Enter number of other rooms “
Input numRooms
// Check for invalid input
While numRooms < 0
Display “Invalid input – number of other rooms cannot be negative
// Read the number of other rooms again
Display “Re-enter number of other rooms “
Input numRooms
// Call function to calculate the total cleaning bill
totalBill = calcBill(numBathrooms, numRooms)
// Display the bill
Display “Your cleaning bill is “, totalBill
// Read the next name
Display “Enter last name or ‘zzz’ when done: “
Input name
// End While
// Display parting message
Display “Program will now end”
End module main
Begin function calcBill(Integer bathrooms, rooms)
// Declare variables
Declare Real bill = 40.0 // Initialize to the base amount
// Set up constant for base rate and additional charges
Constant Real BATHROOM_RATE = 15.00
Constant Real ROOM_RATE = 10.00
// Calculate bill
bill = bill + (bathrooms * BATHROOM_RATE) + (rooms * ROOM_RATE)
Return bill
End function calcBill
Explanation / Answer
Here is the code. If u face any issue u can leave a comment, will try to solve for sure:
#include <iostream>
using namespace std;
void calcBill(int noOfBathRooms,int noOfRooms)
{
double bill=40.0;
int bathRoom_rate=15.0;
int room_rate=10.0;
bill=bill+(noOfBathRooms*bathRoom_rate)+(noOfRooms*room_rate);
cout<<"Total Bill::"<<bill<<endl;
}
int main() {
// your code goes here
char lastName[100];
double totalBill;
int noOfBathRooms;
int noOfRooms;
cout<<"Enter the Last Name or 'ZZZZ' when done ";
cin>>lastName;
while(!(lastName == "ZZZZ"))
{
cout<<"Enter the number of Bathrooms ";
cin>>noOfBathRooms;
while(noOfBathRooms < 0)
{
cout<<"Invalid input – number of bathrooms cannot be negative ";
cout<<"Re-enter number of bathrooms ";
cin>>noOfBathRooms;
}
cout<<"Enter the Number of rooms ";
cin>>noOfRooms;
while(noOfRooms<0)
{
cout<<"Invalid input – number of other rooms cannot be negative";
cout<<"Re-enter number of other rooms ";
cin>>noOfRooms;
}
calcBill(noOfBathRooms, noOfRooms);
}
return 0;
}