Hi there! I have written a program with fixed costs for a vacation. I need to add sales tax in for the total amount but this needs to be floating. Also, I had intended this to be a user input based program, but without knowing the float code for calculation, I dont know how to proceed.Any pointers or help would be awesome! Thanks!
#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;
}