-
March 9th, 2009, 02:13 PM
#1
Help with adding sales tax and float function
Hi there! I have put together a Spring break calculator and I am unsure how to add the sales tax to the cost and declare the float function for costs. Any help would be great! Just need help being pointed in the right direction! Thanks!!!
Code:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
//declare function prototypes
void getInput(double& airtravelCost, int& hotelCost, int& foodCost, int& entCost, double& tripCost);
double airtravelCalculator();
int hotelCalculator();
int foodCalculator();
int entCalculator();
double printResults(double airtravelCost, int hotelCost, int foodCost, int entCost, double tripCost);
//named constants
double planeGasPerMile = .65;
int downtownHotel = 85;
int cheapHotel= 45;
int hostelHotel = 25;
int fastFoodMeal = 4;
int mediumFoodMeal = 8;
int fancyFoodMeal = 20;
int _tmain(int argc, _TCHAR* argv[])
{
//declare all variables in program
double airtravelCost;
//int airtravelMiles;
int hotelCost;
//int nightsIndowntown;
//int nightsIncheap;
//int nightsInhostel;
int foodCost;
//int mealsInFastFood;
//int mealsInMediumFood;
//int mealsInFancyFood;
int entCost;
double tripCost;
char newSpringbreak;
//Welcome message
cout << "Welcome to the spring break cost calculator." << endl;
cout << "Would you like to calculate the cost of a spring break?" << endl;
cout << "Please select 'Y' for yes or 'N' for no:" << endl;
cin >> newSpringbreak;
switch(newSpringbreak)
{
case 'Y': case 'y':
break;
case 'N': case 'n':
break;
default:
cout << "You have chosen an invalid selection." << endl;
cout << "Please select 'Y' for yes or 'N' for no:" << endl;
cin >> newSpringbreak;
break;
}
//calling functions
while (newSpringbreak == 'Y'|| newSpringbreak == 'y')
{
getInput(airtravelCost, hotelCost, foodCost, entCost, tripCost);
printResults(airtravelCost, hotelCost, foodCost, entCost, tripCost);
cout << "Would you like to calculate the cost of a spring break?" << endl;
cout << "Please select 'Y' for yes or 'N' for no:" << endl;
cin >> newSpringbreak;
switch(newSpringbreak)
{
case 'Y': case 'y':
break;
case 'N': case 'n':
break;
default:
cout << "You have chosen an invalid selection." << endl;
cout << "Please select 'Y' for yes or 'N' for no:" << endl;
cin >> newSpringbreak;
break;
}
}
return 0;
}
void getInput(double& airtravelCost, int& hotelCost, int& foodCost, int& entCost, double& tripCost)
{
airtravelCost = airtravelCalculator();
hotelCost = hotelCalculator();
foodCost = foodCalculator();
entCost = entCalculator();
}
double airtravelCalculator()
{
//declare variables
double airtravelCost;
int airtravelMiles;
cout << "Enter the total miles traveled by plane: ";
cin >> airtravelMiles;
cout << endl;
flightCost = (airtravelMiles * planeGasPerMile);
return airtravelCost;
}
int hotelCalculator()
{
//declare variables
int hotelCost;
int nightsIndowntown;
int nightsIncheap;
int nightsInhostelr;
cout << "How many nights will be spent in downtown hotels: ";
cin >> nightsIndowntown;
cout << endl;
cout << "How many nights will be spent in cheap hotels: ";
cin >> nightsIncheap;
cout << endl;
cout << "How many nights will be spent in hostel hotels: ";
cin >> nightsInhostel;
cout << endl;
hotelCost = (nightsIndowntown * downtownHotel + nightsIncheap * cheapHotel + nightsInhostel * hostelHotel);
return hotelCost;
}
int foodCalculator()
{
//declare variables
int foodCost;
int mealsInFastFood;
int mealsInMediumFood;
int mealsInFancyFood;
cout << "How many meals will be eaten in fast food restaurants: ";
cin >> mealsInFastFood;
cout << endl;
cout << "How many meals will be eaten in medium priced restaurants: ";
cin >> mealsInMediumFood;
cout << endl;
cout << "How many meals will be eaten in high priced restaurants: ";
cin >> mealsInFancyFood;
cout << endl;
foodCost = (mealsInFastFood * fastFoodMeal + mealsInMediumFood * mediumFoodMeal + mealsInFancyFood * fancyFoodMeal);
return foodCost;
}
int entCalculator()
{
//declare variables
int entCost;
cout << "How much will you spend on entertainment: ";
cin >> entCost;
cout << endl;
return entCost;
}
double printResults(double airtravelCost, int hotelCost, int foodCost, int entCost, double tripCost)
{
//Calculates cost of entire trip
tripCost = (airtravelCost + hotelCost + foodCost + entCost);
//Displaying output
cout << "The cost of the airtravel is: " << flightCost << endl;
cout << "The total cost of the hotels is: " << hotelCost << endl;
cout << "The total cost of food is: " << foodCost << endl;
cout << "The total cost of entertainment is: " << entCost << endl;
cout << "The entire cost of the trip is: " << tripCost << endl;
return tripCost;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|