### Where is my mistakes? Especially in the calculation process.

 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 #include #include #include #include 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
 123 if (useCreditCard == 'C') discount = price * 0.15; discPrice = totalpayment - discount;

is the same as:

 12345 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.