here is my code. I can't get it to work if i pick 2 for room and 7 for floor it should be 72.00 but it says 55.00 and i can't fingure out why. Please help me.
#include<iostream>
using namespace std;
int main()
{
int room;
int floor;
int night;
cout << "Please enter the type of room you would like. 1 for single, "
<< "2 for a double, or 3 for a suite " << endl;
cin >> room;
if(room == 1)
cout << "You would like a single " << endl;
else
if(room == 2)
cout << "You would like a double " << endl;
else
if(room == 3)
cout << "You would like a suite " << endl;
else
cout << "Please try again. You need to pick between 1,2 and 3 " << endl;
cout << "Please enter the floor you wish to stay on, please enter from 1 though 12 " << endl;
cin >> floor;
if(floor == 1)
cout << "You wish to stay on floor 1 " << endl;
else
if(floor == 2)
cout << "You wish to stay on floor 2 " << endl;
else
if(floor == 3)
cout << "You wish to stay on floor 3 " << endl;
else
if(floor == 4)
cout << "You wish to stay on floor 4 " << endl;
else
if(floor == 5)
cout << "You wish to stay on floor 5 " << endl;
else
if(floor == 6)
cout << "You wish to stay on floor 6 " << endl;
else
if(floor == 7)
cout << "You wish to stay on floor 7 " << endl;
else
if(floor == 8)
cout << "You wish to stay on floor 8 " << endl;
else
if(floor == 9)
cout << "You wish to stay on floor 9 " << endl;
else
if(floor == 10)
cout << "You wish to stay on floor 10 " << endl;
else
if(floor == 11)
cout << "You wish to stay on floor 11 " << endl;
else
if(floor == 12)
cout << "You wish to stay on floor 12 " << endl;
else
cout << "Try again. Please enter a number between 1 and 12" << endl;
cout << "Please enter the number of nights you wish to stay " << endl;
cin >> night;
if(room == 1 && floor == 1 || floor == 2 || floor == 3 || floor == 4 || floor == 5)
cout << "The single night price for your room is 45.00 " << endl;
else
if(room == 2 && floor == 1 || floor == 2 || floor == 3 || floor == 4 || floor == 5)
cout << "The single night price for your room is 60.00 " << endl;
else
if(room == 3 && floor == 1 || floor == 2 || floor == 3 || floor == 4 || floor == 5)
cout << "The single night price for your room is 130.00 " << endl;
else
if(room == 1 && floor == 6 || floor == 7 || floor == 8 || floor == 9 || floor == 10 || floor == 11)
cout << "The single night price for your room is 55.00 " << endl;
else
if(room == 2 && floor == 6 || floor == 7 || floor == 8 || floor == 9 || floor == 10 || floor == 11)
cout << "The single night price for you room is 72.00 " << endl;
else
if(room == 3 && floor == 6 || floor == 7 || floor == 8 || floor == 9 || floor == 10 || floor == 11)
cout << "The single night price for you room is 215.00 " << endl;
system("pause");
return 0;
actually if you pick room 2 and floor 7
the first condition that is true valued is
if(room == 1 && floor == 6 || floor == 7 || floor == 8 || floor == 9 || floor == 10 || floor == 11)
thats way is printed out cout << "The single night price for your room is 55.00 " << endl;
take a look
&& and || have the same precedence
then if
room == 1 is false
floor == 6 is false
floor == 7 is true
and the other conditions doesn't matter
what we got
false && false || true || x || x || is true if you evaluate it from left to rigth
false &&false = false
false || true = true
true || x = true...
take the precedence in mind...
i got it working but i have to show a 10% discount if the nights stayed is over 4 how would i go about doing that please. i know to multipy and then subtract 10% but the room price is not saved anywhere.
Instead of cout-ing all of those room quotes, instead assign the room price to a variable. Then after all of your if statements, announce the price using the variable. You will then have it for computing a percentage.
Just one last thing. When i try to get a single room with 1 on floor 12 there should be a error and there is, but it also does a bunch on random numbers that shouldn't be there. here is my code.
#include<iostream>
using namespace std;
int main()
{
int room;
int floor;
int night;
float price;
cout << "Please enter the type of room you would like. 1 for single, "
<< "2 for a double, or 3 for a suite " << endl;
cin >> room;
if(room == 1)
cout << "You would like a single " << endl;
else
if(room == 2)
cout << "You would like a double " << endl;
else
if(room == 3)
cout << "You would like a suite " << endl;
else
cout << "Please try again. You need to pick between 1,2 and 3 " << endl;
cout << "Please enter the floor you wish to stay on, please enter from 1 though 12 " << endl;
cin >> floor;
if(floor < 1 || floor > 12)
cout << "Try again. Please enter a number between 1 and 12" << endl;
else
cout << "You wish to stay on floor " << floor << endl;
cout << "Please enter the number of nights you wish to stay " << endl;
cin >> night;
if( 1 <= floor && floor <= 5)
{
if (room ==1 ) price = 45 ;
if (room ==2 ) price = 60 ;
if (room ==3 ) price = 130 ;
}
else
if(6 <= floor && floor <= 11)
{
if (room ==1 ) price = 55 ;
if (room ==2 ) price = 72 ;
if (room ==3 ) price = 215 ;
}
else
if(12 == floor)
{
if (room == 1 ) cout << "Sorry, we don't have single rooms on the 12th floor " << endl;
if (room == 2 ) price = 120 ;
if (room == 3 ) price = 350 ;
}
cout << "The single night price for you room is " << price << endl;
cout << "your account is: " << (price * night) ;
if (night > 4 )
{ cout << "you have a discount of 10% : " << (price*night*0.1) << endl;
cout << "your total bill: " << (price*night)*(0.9) << endl;
}
system("pause");
return 0;
}