Help with creating hotel bill

I am trying to create a code that will create a hotel bill. The program shall prompt the user for some numerical values, read in those values, include those values when calculating results, and then print the bill on the screen.

This is what I have so far.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
double checkinmonth;
double checkinday;
double checkinyear;
double roomnumber;
double costofroom;
double amountdue;
const double STATE_TAX = 7.75;
const double ROOM_TAX = 4.00;

cout<<"Enter check in month:";
cin>> checkinmonth;

cout<<"Enter check in day:";
cin>> checkinday;

cout<<"Enter check in year:";
cin>> checkinyear;

cout<<"Enter room number:";
cin>> roomnumber;

cout<<"Enter cost of room:";
cin>> costofroom;

if 


cout << fixed << setprecision(2)<< "Amount due: " << amountdue;
}
Last edited on
closed account (E0p9LyTq)
PLEASE learn to use code tags, it makes reading and commenting on your code MUCH easier.
http://www.cplusplus.com/articles/jEywvCM9/

Hint: you can edit your post and add code tags.

With that said what you done so far is a good start. With unit billing there are only two things needed: number of units and the price of each unit. The rest of the data you retrieve -- date and room number, etc. -- is only used to make a bill look "pretty."

Add in asking the user for the length of stay, calculate the bill based on the number of days times the room rate, print it all out and you are done.

You've done most of the work already, a bit more code gets you over the finish line.

How you format the data output is entirely up to you and your instructions.
Last edited on
Ok so then how am I able to make it look like this in the end?


Post Date Description Comment Amount
---------- ----------- ------- ------
3/14/2011 Room Charge # 118 72.10
3/14/2011 State Tax (7.75%) 5.59
3/14/2011 Room Tax (4.00%) 2.88
----------
Balance Due: 80.57



closed account (E0p9LyTq)
If I were to do it I'd use the Boost Date_Time libraries
https://www.boost.org/doc/libs/1_67_0/doc/html/date_time.html

and the Boost Format library.
https://www.boost.org/doc/libs/1_67_0/libs/format/

Without Boost I might do something crude such as (very simplified example):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <iomanip>

int main()
{
   const double STATE_TAX = 7.75;
   const double ROOM_TAX  = 4.00;

   unsigned short check_in_month = 6;
   unsigned short check_in_day   = 14;
   unsigned short check_in_year  = 2018;
   unsigned short room_number    = 118;

   double cost_of_room           = 72.10;
   // double amountdue;

   std::cout << check_in_month << '/' << check_in_day << '/' << check_in_year << '\t';
   std::cout << "Room # " << room_number << '\t';
   std::cout << "Charge: " << std::fixed << std::setprecision(2) << cost_of_room;

   std::cout << '\n';
}

6/14/2018       Room # 118      Charge: 72.10

Quick and dirty, but it works. Somewhat.
Last edited on
Topic archived. No new replies allowed.