Design an algorithm to prepare a daily hotel charge report. Input is a room numb
ID: 3621232 • Letter: D
Question
Design an algorithm to prepare a daily hotel charge report. Input is a room number, customer name, cost of the room, and cost of meals. Output is a hotel charge report that will contain the room number, customer name, room charge, meal charges, and a final total of all charges. After all records have been processed, the total number of rooms rented, the total room charges, total meal charges, and a final total of all charges are to be printed. A room number of 000 will be used to signal the end of the input.Explanation / Answer
#include #include #include using namespace std; void printRoom(string rNum, string name, double rCost, double mealCost) { printf("%-13s: %s ", "Room Number", rNum.c_str()); printf("%-13s: %s ", "Customer Name", name.c_str()); printf("%-13s: %.2f ", "Room Charge", rCost); printf("%-13s: %.2f ", "Meal Charges", mealCost); printf("%-13s: %.2f ", "Total", rCost + mealCost); } int main() { string rNum; string name; double rCost, mealCost; int i=0; double mealSum=0; double roomSum=0; printf("Please enter room number, 000 to exit: "); cin >> rNum; while (rNum != "000") { printf("Please enter customer name: "); getline(cin, name); // burn the newline getline(cin, name); // (using getline to avoid spaces in names) printf("Please enter room cost: "); cin >> rCost; printf("Please enter meal cost: "); cin >> mealCost; printf(" "); i++; mealSum += mealCost; roomSum += rCost; printRoom(rNum, name, rCost, mealCost); printf("Please enter room number, 000 to exit: "); cin >> rNum; } if (i == 1) printf(" %d room was rented ", i); else printf(" %d rooms were rented ", i); printf("%.2f room charges were accrued ", roomSum); printf("%.2f meal charges were accrued ", mealSum); printf("%.2f total charges were accrued ", roomSum + mealSum); return 0; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.