Where is my mistakes? Especially in the calculation process.

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <conio.h>
#include <math.h>
#include <iomanip>
using namespace std;

main ()
{
	char name [10], typeRoom;
	int numDay, priceRoom;
	float price, discount, tax, totalpayment, useCreditCard, discPrice;
	
	cout << "Enter your name: ";
	cin >> name;
	cout << "Enter number of days that you plan to stay: ";
	cin >> numDay;
	cout << "Choose your type of room [P-Superior, D-Deluxe, S-Standard, E-Economy] : ";
	cin >> typeRoom;
	cout << "If you use a credit card to pay, type 'C' : ";
	cin >> useCreditCard;
	cout << endl;
	cout << "-------------------------------------------------" << endl;
	cout << endl;
	cout << "              ";
	cout << "\tWELCOME TO SEMARAK CINTA HOTEL\t";
	cout << "              " << endl;
	cout << "___________________________________________________________" << endl;
	cout << "NAME : " << name << endl;
	cout << "TYPE OF ROOM : " << typeRoom << endl;
	cout << "NUMBER OF DAYS : " << numDay << endl;
	cout << "PRICE BEFORE TAX : RM " << price << endl;
	cout << "TOTAL PAYMENT : RM " << totalpayment << endl;
	cout << endl;
	cout << "                         ";
	cout << "THANK YOU";
	cout << "                         " << endl;
	cout << "                     ";
	cout << "PLEASE COME AGAIN\t";
	cout << "                 " << endl;
	cout << "___________________________________________________________" << endl;


	switch (typeRoom)
		{
			case 'P':
				price = numDay * 175.00;
				tax = price * 0.1;
				totalpayment = price + tax;
				if (useCreditCard == 'C')
					discount = price * 0.15;
					discPrice = totalpayment - discount;
			case 'D':
				price = numDay * 155.00;
				tax = price * 0.1;
				totalpayment = price + tax;
				if (useCreditCard == 'C')
					discount = price * 0.15;
					discPrice = totalpayment - discount;		
			case 'S':
				price = numDay * 120.00;
				tax = price * 0.1;
				totalpayment = price + tax;
				if (useCreditCard == 'C')
					discount = price * 0.15;
					discPrice = totalpayment - discount;
			case 'E':
				price = numDay * 100.00;
				tax = price * 0.1;
				totalpayment = price + tax;
				if (useCreditCard == 'C')
					discount = price * 0.15;
					discPrice = totalpayment - discount;			
		}
	getch ();
}


Here is my full coding program, can someone tell me what is my mistake because I can run my program but I didnt get a perfect answer as my final output display. I know there are problem in my calculation part but I just dont how to correct it. Please help me. Oh, by the way, I'm using Dev C++ for my programming.
Last edited on
You're doing all your calculations AFTER you've displayed the results.

You need to do your calculations, and THEN show them on the screen. It's impossible to show the results before you've actually calculated them.

Also, if blocks; you're doing them wrong. Use braces.

This code
1
2
3
if (useCreditCard == 'C')
       discount = price * 0.15;
       discPrice = totalpayment - discount;

is the same as:

1
2
3
4
5
if (useCreditCard == 'C')
{
       discount = price * 0.15;
}
discPrice = totalpayment - discount;

Use braces so you can tell what is inside the if block.
Last edited on
Thank you, you help me a lot.
Topic archived. No new replies allowed.