pbracing33b
09-30-2012, 02:00 AM
I have and issue with my code, I have the code almost dead on except for one thing and it is a math issue, and I am not that good at math to figure out how to calculate this formula.
Here is what we need to do for this program:
The Holiday Travel Agency is putting together some travel packages for spring break, and they would like a program that will help them calculate the cost of a customer’s trip. They have 4 destinations which they will offer at different prices:
Destination Rate per day(hotel) Air fare
Florida $ 70.00 $ 175.55
Texas $ 60.00 $ 225.98
Cancun $100.00 $ 474.89
Bahamas $ 95.00 $ 355.98
In order to encourage people to sign up early and stay longer, they have the following discounts scheduled.
1. If they will be staying for more than 6 days there will be a price reduction based on their destination. (Hint: a nested if might work nicely here)
- Florida and Cancun: one day free
- Texas and Bahamas: 50% off the airfare
2. There is also a discount based on how far ahead the reservation is made. This discount is to be applied to the bill after long stay discounts has been deducted.
(you can use a subtotal)
- Reservation 1 - 4 weeks in advance no discount
- Reservation 5 - 6 weeks in advance 5% discount
- Reservation 7-9 weeks in advance 8% discount
- Reservation 10 or more weeks in advance 10% discount
Input: For each customer, the user will need to enter the number of weeks before the trip, the number of days they are staying and the destination (“F for Florida, “T” for Texas, “C” for Cancun, or “B” for Bahamas). Use a menu for the destinations. The input must be in the specific order listed here! Use good prompts to ask the user for the data. After you input the destination, use an if/else/if statement to change the destination letter to the destination word. ( change “F” which the user will enter to “Florida” which will be used in your output.)
Output: The input and output of the Project should look similar to the following. Use a desk check to validate your result. It is possible that the discount could be zero. The final bill should be the cost of hotel plus the cost of airfare minus the two discounts.
And here is my code:
// Program #3 – Vacation Program
// Programmer: 236_Blair_Phil_P3
// Class: CS 2010, Fall 2012
// Class Time: 1030-1120
// Due Date: Oct. 10, 2012
// Purpose of program: This program is going to help a user figure out when to schedule or how to save money and schedule early for their vacation. How much they saved is based upon when they book their vacation.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
//Declaration Section
double rate;
double discountRate;
int days;
int weeks;
char destination;
double discount;
double earlyDiscount;
double airFare;
double airFareDiscount;
double total;
string location;
double cost;
double discount1;
//Constants
const double FLORIDA_RATE = 70.00;
const double FLORIDA_AIR_FARE = 175.55;
const double TEXAS_RATE = 60.00;
const double TEXAS_AIR_FARE = 225.98;
const double CANCUN_RATE = 100.00;
const double CANCUN_AIR_FARE = 474.89;
const double BAHAMAS_RATE = 95.00;
const double BAHAMAS_AIR_FARE = 355.98;
//Input Section
cout<<"Enter the number of weeks before the trip: ";
cin>>weeks;
cout<<"How many days are you staying: ";
cin>>days;
cout<<"Please enter your destination: "<<endl;
cout<<"F for Florida"<<endl;
cout<<"T for Texas"<<endl;
cout<<"C for Cancun"<<endl;
cout<<"B for Bahamas"<<endl;
cout<<"=======>";
cin>>destination;
//Processing Section
if(destination == 'F'|| destination == 'f')
{
location = "Florida";
rate = FLORIDA_RATE * days;//possibly move these variables up to the declaration section
airFare = FLORIDA_AIR_FARE;
cost = rate + airFare;
discount = FLORIDA_RATE * 1;
discountRate = rate + airFare - discount;
if (days > 6)
{
discount;
discountRate;
}
else
{
discount = 0;
}
if(weeks <= 4)//early discount
{
earlyDiscount = 0;
}
else if(weeks <= 6)
{
earlyDiscount = .05;
}
else if(weeks <= 9)
{
earlyDiscount = .08;
}
else if(weeks >= 10)
{
earlyDiscount = .10;
}
else
{
discount = 0;
}
}
else if(destination == 'T'|| destination == 't')
{
location = "Texas";
rate = TEXAS_RATE* days;
airFare = TEXAS_AIR_FARE;
if (days > 6)
{
airFareDiscount = airFare * .50;
discount = airFareDiscount;
discountRate = rate + airFare - discount;
}
else
{
discount = 0;
}
if(weeks <= 4)//early discount
{
earlyDiscount = 0;
}
else if(weeks <= 6)
{
earlyDiscount = discountRate * .05;
}
else if(weeks <= 9)
{
earlyDiscount = discountRate * .08;
}
else if(weeks >= 10)
{
earlyDiscount = discountRate * .10;
}
}
else if(destination == 'C'|| destination == 'c')
{
location = "Cancun";
rate = CANCUN_RATE * days;
airFare = CANCUN_AIR_FARE;
if (days > 6)//long stay discount
{
discount = CANCUN_RATE * 1;
discountRate = rate + airFare - discount;
}
else
{
discount = 0;
}
if(weeks <= 4)//early discount
{
earlyDiscount = 0;
}
else if(weeks <= 6)
{
earlyDiscount = discountRate * .05;
}
else if(weeks <= 9)
{
earlyDiscount = discountRate * .08;
}
else if(weeks >= 10)
{
earlyDiscount = discountRate * .10;
}
}
else if(destination == 'B'|| destination == 'b')
{
location = "Bahamas";
rate = BAHAMAS_RATE * days;
airFare = BAHAMAS_AIR_FARE;
if (days > 6)//long discount
{
airFareDiscount = airFare * .50;
discount = airFareDiscount;
discountRate = rate + airFare - discount;
}
else
{
discount = 0;
}
if(weeks <= 4)//early discount
{
earlyDiscount = 0;
}
else if(weeks <= 6)
{
earlyDiscount = discountRate * .05;
}
else if(weeks <= 9)
{
earlyDiscount = discountRate * .08;
}
else if(weeks >= 10)
{
earlyDiscount = discountRate * .10;
}
discount1 = discountRate * earlyDiscount;
total = rate + airFare - discount - discount1;
}
else
{
cout<<"Please enter a valid Character"<<endl;
system("pause");
return 0;
}
//Output Section
cout << fixed << showpoint << setprecision(2);
cout<<endl;
cout<<"=================================================================="<<endl;
cout<<"=================================================================="<<endl;
cout<<" Holdiday Travel Agency"<<endl;
cout<<" Customer Bill"<<endl;
cout<<endl;
cout<<"Destination: "<<location<<endl;
cout<<"Number of weeks to go: "<<weeks<<endl;
cout<<"Number of days to stay: "<<days<<endl;
cout<<endl;
cout<<"Cost of Hotel: $ "<<setw(10)<<rate<<endl;
cout<<"Cost of Airfare: $ "<<setw(10)<<airFare<<endl;
cout<<"Longer stay discount: $ "<<setw(10)<<discount<<endl;
cout<<"Early signup discount: $ "<<setw(10)<<discount1<<endl;
cout<<endl;
cout<<"Final Bill: $ "<<setw(10)<<total<<endl;
cout<<"=================================================================="<<endl;
cout<<"=================================================================="<<endl;
system("pause");
return 0;
}
The only part that I don't have working properly is if the user books his stay 4 or more weeks in advance and only stays less then 6 days. If this happens my calculations are off. So I'm not sure how to correct this issue, I know it is the way my math should be laid out, but I am not sure how to lay out this formula for this program,
any help that is given would be greatly appreciated.
Thanks.
oh and btw this is in visual studio C++
Here is what we need to do for this program:
The Holiday Travel Agency is putting together some travel packages for spring break, and they would like a program that will help them calculate the cost of a customer’s trip. They have 4 destinations which they will offer at different prices:
Destination Rate per day(hotel) Air fare
Florida $ 70.00 $ 175.55
Texas $ 60.00 $ 225.98
Cancun $100.00 $ 474.89
Bahamas $ 95.00 $ 355.98
In order to encourage people to sign up early and stay longer, they have the following discounts scheduled.
1. If they will be staying for more than 6 days there will be a price reduction based on their destination. (Hint: a nested if might work nicely here)
- Florida and Cancun: one day free
- Texas and Bahamas: 50% off the airfare
2. There is also a discount based on how far ahead the reservation is made. This discount is to be applied to the bill after long stay discounts has been deducted.
(you can use a subtotal)
- Reservation 1 - 4 weeks in advance no discount
- Reservation 5 - 6 weeks in advance 5% discount
- Reservation 7-9 weeks in advance 8% discount
- Reservation 10 or more weeks in advance 10% discount
Input: For each customer, the user will need to enter the number of weeks before the trip, the number of days they are staying and the destination (“F for Florida, “T” for Texas, “C” for Cancun, or “B” for Bahamas). Use a menu for the destinations. The input must be in the specific order listed here! Use good prompts to ask the user for the data. After you input the destination, use an if/else/if statement to change the destination letter to the destination word. ( change “F” which the user will enter to “Florida” which will be used in your output.)
Output: The input and output of the Project should look similar to the following. Use a desk check to validate your result. It is possible that the discount could be zero. The final bill should be the cost of hotel plus the cost of airfare minus the two discounts.
And here is my code:
// Program #3 – Vacation Program
// Programmer: 236_Blair_Phil_P3
// Class: CS 2010, Fall 2012
// Class Time: 1030-1120
// Due Date: Oct. 10, 2012
// Purpose of program: This program is going to help a user figure out when to schedule or how to save money and schedule early for their vacation. How much they saved is based upon when they book their vacation.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
//Declaration Section
double rate;
double discountRate;
int days;
int weeks;
char destination;
double discount;
double earlyDiscount;
double airFare;
double airFareDiscount;
double total;
string location;
double cost;
double discount1;
//Constants
const double FLORIDA_RATE = 70.00;
const double FLORIDA_AIR_FARE = 175.55;
const double TEXAS_RATE = 60.00;
const double TEXAS_AIR_FARE = 225.98;
const double CANCUN_RATE = 100.00;
const double CANCUN_AIR_FARE = 474.89;
const double BAHAMAS_RATE = 95.00;
const double BAHAMAS_AIR_FARE = 355.98;
//Input Section
cout<<"Enter the number of weeks before the trip: ";
cin>>weeks;
cout<<"How many days are you staying: ";
cin>>days;
cout<<"Please enter your destination: "<<endl;
cout<<"F for Florida"<<endl;
cout<<"T for Texas"<<endl;
cout<<"C for Cancun"<<endl;
cout<<"B for Bahamas"<<endl;
cout<<"=======>";
cin>>destination;
//Processing Section
if(destination == 'F'|| destination == 'f')
{
location = "Florida";
rate = FLORIDA_RATE * days;//possibly move these variables up to the declaration section
airFare = FLORIDA_AIR_FARE;
cost = rate + airFare;
discount = FLORIDA_RATE * 1;
discountRate = rate + airFare - discount;
if (days > 6)
{
discount;
discountRate;
}
else
{
discount = 0;
}
if(weeks <= 4)//early discount
{
earlyDiscount = 0;
}
else if(weeks <= 6)
{
earlyDiscount = .05;
}
else if(weeks <= 9)
{
earlyDiscount = .08;
}
else if(weeks >= 10)
{
earlyDiscount = .10;
}
else
{
discount = 0;
}
}
else if(destination == 'T'|| destination == 't')
{
location = "Texas";
rate = TEXAS_RATE* days;
airFare = TEXAS_AIR_FARE;
if (days > 6)
{
airFareDiscount = airFare * .50;
discount = airFareDiscount;
discountRate = rate + airFare - discount;
}
else
{
discount = 0;
}
if(weeks <= 4)//early discount
{
earlyDiscount = 0;
}
else if(weeks <= 6)
{
earlyDiscount = discountRate * .05;
}
else if(weeks <= 9)
{
earlyDiscount = discountRate * .08;
}
else if(weeks >= 10)
{
earlyDiscount = discountRate * .10;
}
}
else if(destination == 'C'|| destination == 'c')
{
location = "Cancun";
rate = CANCUN_RATE * days;
airFare = CANCUN_AIR_FARE;
if (days > 6)//long stay discount
{
discount = CANCUN_RATE * 1;
discountRate = rate + airFare - discount;
}
else
{
discount = 0;
}
if(weeks <= 4)//early discount
{
earlyDiscount = 0;
}
else if(weeks <= 6)
{
earlyDiscount = discountRate * .05;
}
else if(weeks <= 9)
{
earlyDiscount = discountRate * .08;
}
else if(weeks >= 10)
{
earlyDiscount = discountRate * .10;
}
}
else if(destination == 'B'|| destination == 'b')
{
location = "Bahamas";
rate = BAHAMAS_RATE * days;
airFare = BAHAMAS_AIR_FARE;
if (days > 6)//long discount
{
airFareDiscount = airFare * .50;
discount = airFareDiscount;
discountRate = rate + airFare - discount;
}
else
{
discount = 0;
}
if(weeks <= 4)//early discount
{
earlyDiscount = 0;
}
else if(weeks <= 6)
{
earlyDiscount = discountRate * .05;
}
else if(weeks <= 9)
{
earlyDiscount = discountRate * .08;
}
else if(weeks >= 10)
{
earlyDiscount = discountRate * .10;
}
discount1 = discountRate * earlyDiscount;
total = rate + airFare - discount - discount1;
}
else
{
cout<<"Please enter a valid Character"<<endl;
system("pause");
return 0;
}
//Output Section
cout << fixed << showpoint << setprecision(2);
cout<<endl;
cout<<"=================================================================="<<endl;
cout<<"=================================================================="<<endl;
cout<<" Holdiday Travel Agency"<<endl;
cout<<" Customer Bill"<<endl;
cout<<endl;
cout<<"Destination: "<<location<<endl;
cout<<"Number of weeks to go: "<<weeks<<endl;
cout<<"Number of days to stay: "<<days<<endl;
cout<<endl;
cout<<"Cost of Hotel: $ "<<setw(10)<<rate<<endl;
cout<<"Cost of Airfare: $ "<<setw(10)<<airFare<<endl;
cout<<"Longer stay discount: $ "<<setw(10)<<discount<<endl;
cout<<"Early signup discount: $ "<<setw(10)<<discount1<<endl;
cout<<endl;
cout<<"Final Bill: $ "<<setw(10)<<total<<endl;
cout<<"=================================================================="<<endl;
cout<<"=================================================================="<<endl;
system("pause");
return 0;
}
The only part that I don't have working properly is if the user books his stay 4 or more weeks in advance and only stays less then 6 days. If this happens my calculations are off. So I'm not sure how to correct this issue, I know it is the way my math should be laid out, but I am not sure how to lay out this formula for this program,
any help that is given would be greatly appreciated.
Thanks.
oh and btw this is in visual studio C++