• (2 Pages)
• 1
• 2

Reputation:

# Cancun Mexican Resort algorithm

Posted 26 July 2010 - 12:21 AM

Hey, sup guys?

This is not a "DO MY HOMEWORK FOR ME" post, so relax.

I'm just stuck and need a nudge.

I'm having trouble remembering how to continue and end the program during my first if/else statement.
Also, would you tell me if my variables look right? (I feel like I did something wrong)
Anyone who could show me what I am doing wrong, or push me in the right direction, I would probably hug you.

Here is my code so far

```//CISFinal.cpp enables guests to make
//reservations at the Cancun Mexican Resort

#include <iostream>
#include <iomanip>

using std::cout;
using std::cin;
using std::endl;

int main()
{
//declare variables
double roomTotal = 0.00;
double roomPrice = 0.00;
int numNights = 0;
double roomTax = 0.00;
const double PRICE1 = 280.00;
const double PRICE2 = 310.00;
const double PRICE3 = 235.00;
const double PRICE4 = 255.00;
char curType = ' ';
char goOn = ' ';
double transCost = 0.00;
double finalTotal = 0.0;
int dayTrans = 0;
const double BUSDAYS = 15.00;
const double BUSTOUR = 10.00;

//confirm continue
cout << "Do you want to continue? Y/N: ";
cin >> goOn;
if (goOn == 'Y' || goOn == 'y')

```

and here are the instructions for the entire thing.

Rubric and Instructions for final CIS115 project 140 points

You are to create a C++ program that enables a person to make a reservation at the Cancun Mexican Resort.

1.The program should be controlled by a main loop that lets the user answer Y or N to the question,
“Do you want to continue? Y/N” If they answer with a lower case y or a capital Y, the program continues, else the program ends.
5 points

2. Next, a menu as shown below should be displayed using a do while loop.
Before the menu is displayed, use the system (“cls”) command to clear the screen so the menu comes up nice and clean.
10 points

Welcome to the Cancun Mexicana Resort!
*****************************************************
1. King Suite (\$280.00)
2. 2 Queen Beds Suite (\$310.00)
3. King Standard Room (\$235.00)
4. 2 Queen Beds Standard Room (\$255.00)
*****************************************************

If the user enters anything outside the range of 1-4, they should get a message to that effect and be required to enter the menu option again. They should not be able to proceed with the rest of the program until they have entered the correct information.
10 points

3. Once they correctly enter one of the menu numbers, they should be asked for the number of nights.
Please enter the number of nights. Must be greater than 0.
If the number entered is not greater than 0 then tell the user this and do not let them continue until they have entered a number greater than 0.
5 points

4. Next ask them to enter the currency type.
Please enter the currency type: A for American or P for Pesos
If the currency type is not an a or p, make them enter it again until they enter an a or a p. It should not matter if the currency type is a capital a or p.

5 points

5. Next ask them if they need ground transportation.
Do you need ground transportation Y/N? Bus available for 15.00 day
If they do not enter a y or n, do not let them continue until they enter the correct letter.
If they answer y or Y, ask them for the number of days.
How many days do you want transportation - must be greater than zero?
If the number entered is not greater than zero, force them to stay there until the number entered is greater than zero.
5 points

6. Next you ask them if they want a bus tour?
Do you want a bus tour Y/N? Available daily 10.00
Again, validate to make sure they answer with a y or n.
If Y or y, the bus tour total of 10.00 will be included in a variable.
5 points

Calculations:
7. Room rate amounts (280.00, 310.00,235.00 and 255.00) should be declared as constants.
5 points

8. Using a switch structure use the menu options as the case numbers. Example, case 1 would be King Suite(\$280.00) and so on.
Within each case structure create the room total for that menu option by calling a function called getRoomTotal where you will send the room type (should be a constant), the currency type (a or P) and the number of nights. Also in the switch structure, define the room type based on the case option.
20 points

9. In the getRoomTotal function
If the currency type is an A or a,
room total = room price * number of nights * 1
If the currency type if a P or p,
room total = room price * number of nights * 10.5644.
**Note** We are using 10.5644 as the currency conversion rate for Pesos. At any one time it could change. We are using this rate because it keeps everyone’s programs consistent.
10 points

10. Calculate the room tax by multiplying the room total * .15
Get the final total by calling a function called getFinalTotal. You need to pass the variables that include the room total, room tax, days of transportaion and if they are going on a bus tour.
In the function, getTotal you will be using the following calculations.

If the variable for bus tour is a y or Y,
final total is equal to room total+ room tax + days of transportation times 15.00 plus 10.00.

If the variable for bus tour is not equal to y or Y,
final total = room total+room tax+days of transportation times 15.00
20 points

11. Display the reservation information by calling a function called displayInformation. You will pass the number of days, room total, room tax, days of transportation, bus tour, room type , final total, currency type.

The final results should be displayed as follows:
**************************************************************************
Number days you are staying: 2
Room Type: King Suite (\$280.00)
Currency type: American
Tax on room only: 84.00
Room Total only: 560.00
____________________________________________________
Transportation Cost: 30.00
Bus tour: 10.00
____________________________________________________
Total: 684.00
Do you want to make a reservation Y/N

20 points

The initial variables should be reset to their initial values so the user can enter another reservation.

Complete pseudo code – 20 points

Is This A Good Question/Topic? 0

## Replies To: Cancun Mexican Resort algorithm

### #2 novman

Reputation: 1
• Posts: 41
• Joined: 03-June 10

## Re: Cancun Mexican Resort algorithm

Posted 26 July 2010 - 12:29 AM

you can do this many ways, but to exit the program try:

```else EXIT_FAILURE;

```

### #3 taylorc8

• B&

Reputation: 150
• Posts: 1,572
• Joined: 21-July 09

## Re: Cancun Mexican Resort algorithm

Posted 26 July 2010 - 12:37 AM

#1 is making a "main loop" which is usually a while loop in my programs, or a do-while.

You can add that pretty easily, and unless I've misread your directions you only need to ask if they want to continue when they're finished making a reservation, probably the end of the loop.

```do
{
//program logic stuff
}while( goOn == 'y' || goOn == 'Y' );

```

and your variables are supposed to be reset to their initial values, so you can declare them inside the scope of the loop, or outside of it, and assign them all the value you initialized them with.

This post has been edited by taylorc8: 26 July 2010 - 12:38 AM

Reputation:

## Re: Cancun Mexican Resort algorithm

Posted 26 July 2010 - 03:25 PM

I've spent quite a bit of time trying to figure out why "sum" always equals 1, but I haven't been able to figure it out. I don't want to know how to fix it, I just want to know why it's always coming out as 1. I'm obviously reading some part of my code wrong.

(I'm creating an alternating series. When count=2, sum should be .5. Count = 3, sum = .5 + 1/3 = .8333333)

```int main ()

{
cout << setw(15) << left << "n" << "f(n)" << endl;

for (count = 1; count <= 15; count++)
{
cout << setw(15) << left << count;
if (count == 1){
cout << sum << endl;}

else if (count%2 == 0){
sum = sum - (1/count);
cout << sum << endl;}

else if (count%2 != 0){
sum = sum + (1/count);
cout << sum << endl;}
}

```

### #5 Oler1s

• D.I.C Lover

Reputation: 1397
• Posts: 3,884
• Joined: 04-June 09

## Re: Cancun Mexican Resort algorithm

Posted 26 July 2010 - 03:39 PM

Post compileable code.

Reputation:

## Re: Cancun Mexican Resort algorithm

Posted 26 July 2010 - 03:40 PM

This is the first little bit of my final project.

I will post my source code first, followed by the instructions given by my professor.
I am totally lost now and cannot find my error.
Anyone who can help, I will probably hug you.
(any other errors you see, please let me know) (I'm sure there are a few)

```//CISFinal.cpp enables guests to make reservations
//at the Cancun Mexican Resort
//Created/revised by Zach Mock on 7/11/2010

#include <iostream>
#include <iomanip>

using std::cout;
using std::cin;
using std::endl;

int main()
{
//declare variables
double roomTotal = 0.00;
double roomPrice = 0.00;
int numNights = 0;
double roomTax = 0.00;
const double PRICE1 = 280.00;
const double PRICE2 = 310.00;
const double PRICE3 = 235.00;
const double PRICE4 = 255.00;
char curType = ' ';
char goOn = ' ';
double transCost = 0.00;
double finalTotal = 0.0;
int dayTrans = 0;
const double BUSDAYS = 15.00;
const double BUSTOUR = 10.00;
int roomChoice = 0;

//confirm continue
cout << "Do you want to continue? Y/N: ";
cin >> goOn;
if (goOn == 'Y' || goOn == 'y')
{
do
{ system("cls");
cout << "Welcome to the Cancun Mexicana Resort!: " << endl;
cout << "Please select the room type of your choice: " << endl;
cout << "************************************************: " << endl;
cout << "1. King Suite (\$280.00): " << endl;
cout << "2. Queen Beds Suite (\$310.00): " << endl;
cout << "3. King Standard Room (\$235.00): " << endl;
cout << "4. 2 Queen Beds Standard Room (\$255.00): " << endl;
cout << "************************************************: " << endl;
cin >> roomChoice;

if (roomChoice == 1)
{ roomPrice = roomPrice + PRICE1;
}
else if (roomChoice == 2)
{ roomPrice = roomPrice + PRICE2;
}
else if (roomChoice == 3)
{ roomPrice = roomPrice + PRICE3;
}
else if (roomChoice == 4)
{ roomPrice = roomPrice + PRICE4;
}
else
{ cout << "You entered an invalid choice: ";
}
//end if

}
while (roomChoice < 1 && roomChoice >4);
}

else
exit(0);
//end if

```

and here are the instructions for the part I have posted above

Rubric and Instructions for final CIS115 project 140 points

You are to create a C++ program that enables a person to make a reservation at the Cancun Mexican Resort.

1.The program should be controlled by a main loop that lets the user answer Y or N to the question,
“Do you want to continue? Y/N” If they answer with a lower case y or a capital Y, the program continues, else the program ends.
5 points

2. Next, a menu as shown below should be displayed using a do while loop.
Before the menu is displayed, use the system (“cls”) command to clear the screen so the menu comes up nice and clean.
10 points

Welcome to the Cancun Mexicana Resort!
*****************************************************
1. King Suite (\$280.00)
2. 2 Queen Beds Suite (\$310.00)
3. King Standard Room (\$235.00)
4. 2 Queen Beds Standard Room (\$255.00)
*****************************************************

If the user enters anything outside the range of 1-4, they should get a message to that effect and be required to enter the menu option again. They should not be able to proceed with the rest of the program until they have entered the correct information.
10 points

3. Once they correctly enter one of the menu numbers, they should be asked for the number of nights.
Please enter the number of nights. Must be greater than 0.
If the number entered is not greater than 0 then tell the user this and do not let them continue until they have entered a number greater than 0.
5 points

4. Next ask them to enter the currency type.
Please enter the currency type: A for American or P for Pesos
If the currency type is not an a or p, make them enter it again until they enter an a or a p. It should not matter if the currency type is a capital a or p.

Reputation:

## Re: Cancun Mexican Resort algorithm

Posted 26 July 2010 - 03:42 PM

Someone delete my name out of there pls... If my instructor saw that he may freak out.

### #8 jjl

• Engineer

Reputation: 1270
• Posts: 4,998
• Joined: 09-June 09

## Re: Cancun Mexican Resort algorithm

Posted 26 July 2010 - 03:58 PM

You can edit your post, but what problems/errors are you having?

This post has been edited by ImaSexy: 26 July 2010 - 04:00 PM

Reputation:

## Re: Cancun Mexican Resort algorithm

Posted 26 July 2010 - 03:59 PM

Whoops, sorry.

```#include <iostream>
#include <iomanip>

using namespace std;

double sum = 1;
int count = 1;

int main ()

{
cout << setw(15) << left << "n" << "f(n)" << endl;

for (count = 1; count <= 15; count++)
{
cout << setw(15) << left << count;
if (count == 1){
cout << sum << endl;}

else if (count%2 == 0){
sum = sum - (1/count);
cout << sum << endl;}

else if (count%2 != 0){
sum = sum + (1/count);
cout << sum << endl;}
}

return 0;
}

```

Reputation:

## Re: Cancun Mexican Resort algorithm

Posted 26 July 2010 - 04:08 PM

ImaSexy, on 26 July 2010 - 02:58 PM, said:

You can edit your post, but what problems/errors are you having?

It displays "you have entered an invalid choice" for a split second and closes. Plus a few others. (it compiles fine, but doesn't do as the instructions say)
Should I just start over b.c. my code doesn't look right for some reason.
It's an 11 step project, and its due in 23 hours.
I've been up since around 4.am working on it, and I keep falling asleep at the computer.
I guess my brain is just foggy, b.c I cannot see where I have failed.

### #11 Oler1s

• D.I.C Lover

Reputation: 1397
• Posts: 3,884
• Joined: 04-June 09

## Re: Cancun Mexican Resort algorithm

Posted 26 July 2010 - 04:14 PM

See Integer Division.

If both operands in division are integers (for example, in 1 / count, 1 and count are both integer operands), C++ will treat it as integer division.

Make one or both of the operands a double.

Reputation:

## Re: Cancun Mexican Resort algorithm

Posted 26 July 2010 - 04:19 PM

Oler1s, on 26 July 2010 - 03:14 PM, said:

See Integer Division.

If both operands in division are integers (for example, in 1 / count, 1 and count are both integer operands), C++ will treat it as integer division.

Make one or both of the operands a double.

Ohhhhh, that makes so much sense. Thank you!

### #13 Oler1s

• D.I.C Lover

Reputation: 1397
• Posts: 3,884
• Joined: 04-June 09

## Re: Cancun Mexican Resort algorithm

Posted 26 July 2010 - 04:30 PM

Your code works just fine for me. I typed in Y first, then I typed in 1, and the program exited gracefully.

Reputation:

## Re: Cancun Mexican Resort algorithm

Posted 26 July 2010 - 06:15 PM

I am updating from my last post.

I've got everything taken care of except for the part of the instructions that have been underlined and bolded below.

Rubric and Instructions for final CIS115 project 140 points

You are to create a C++ program that enables a person to make a reservation at the Cancun Mexican Resort.

1.The program should be controlled by a main loop that lets the user answer Y or N to the question,
“Do you want to continue? Y/N” If they answer with a lower case y or a capital Y, the program continues, else the program ends.
5 points

2. Next, a menu as shown below should be displayed using a do while loop.
Before the menu is displayed, use the system (“cls”) command to clear the screen so the menu comes up nice and clean.
10 points

Welcome to the Cancun Mexicana Resort!
*****************************************************
1. King Suite (\$280.00)
2. 2 Queen Beds Suite (\$310.00)
3. King Standard Room (\$235.00)
4. 2 Queen Beds Standard Room (\$255.00)
*****************************************************

If the user enters anything outside the range of 1-4, they should get a message to that effect and be required to enter the menu option again. They should not be able to proceed with the rest of the program until they have entered the correct information.
10 points

3. Once they correctly enter one of the menu numbers, they should be asked for the number of nights.
Please enter the number of nights. Must be greater than 0.
If the number entered is not greater than 0 then tell the user this and do not let them continue until they have entered a number greater than 0.
5 points

Here is the code again

```#include <iostream>
#include <iomanip>

using std::cout;
using std::cin;
using std::endl;

int main()
{
//declare variables
double roomTotal = 0.00;
double roomPrice = 0.00;
int numNights = 0;
double roomTax = 0.00;
const double PRICE1 = 280.00;
const double PRICE2 = 310.00;
const double PRICE3 = 235.00;
const double PRICE4 = 255.00;
char curType = ' ';
char goOn = ' ';
double transCost = 0.00;
double finalTotal = 0.0;
int dayTrans = 0;
const double BUSDAYS = 15.00;
const double BUSTOUR = 10.00;
int roomChoice = 0;

//confirm continue
cout << "Do you want to continue? Y/N: ";
cin >> goOn;
if (goOn == 'Y' || goOn == 'y')
{
do
{ system("cls");
cout << "Welcome to the Cancun Mexicana Resort!: " << endl;
cout << "Please select the room type of your choice: " << endl;
cout << "************************************************: " << endl;
cout << "1. King Suite (\$280.00): " << endl;
cout << "2. Queen Beds Suite (\$310.00): " << endl;
cout << "3. King Standard Room (\$235.00): " << endl;
cout << "4. 2 Queen Beds Standard Room (\$255.00): " << endl;
cout << "************************************************: " << endl;
cin >> roomChoice;

if (roomChoice == 1)
{ roomPrice = roomPrice + PRICE1;
}
else if (roomChoice == 2)
{ roomPrice = roomPrice + PRICE2;
}
else if (roomChoice == 3)
{ roomPrice = roomPrice + PRICE3;
}
else if (roomChoice == 4)
{ roomPrice = roomPrice + PRICE4;
}
else
{ cout << "You entered an invalid choice: ";
}
//end if

}
while (roomChoice < 1 && roomChoice >4);
}

else
exit(0);
//end if

return 0;
}
```

Reputation:

## Re: Cancun Mexican Resort algorithm

Posted 26 July 2010 - 06:16 PM

any suggestions would be greatly appreciated.
thanks