-2
#include <iostream>
#include <iomanip>
using namespace std;

//Function prototypes
int getDays();
double getDepartureTime();
double getArrivalTime();
double getAirfareFees();
double getRentalFees();
int getMileageFees();
double getParkingFees(int days);
double getTaxiFees(int days);
double getRegistrationFees();
double getHotelExpenses(int days);
double getBreakfastExpenses(int days, double dTime, double aTime);
double getLunchExpenses(int days, double dTime, double aTime);
double getDinnerExpenses(int days, double dTime, double aTime);

//Global constants
const double MILES = 0.27; //Expense per miles driven
const int PARKING = 6; //Allowed daily parking allowance
const int TAXI = 10; //Allowed daily taxi allowance
const int HOTEL = 90; //Allowed nightly hotel allowance
const int BKFST = 9; //Allowed daily breakfast allowance
const int LUNCH = 12; //Allowed daily lunch allowance
const int DINNER = 16; // ALlowed daily dinner allowance

int main()
{
//Variable Declaration
  double grandTotal = 0, //Total expenses incurred
         allowedTotal = 0, //Total allowable expenses for the trip
         reimburseTotal = 0, //Excess that must be reimbursed, if any
         savedTotal = 0, //Amount saved, if any
         mealExpenses; //Total cost incurred for meals

//Input & function processing

//Bullet 1
  int days = getDays();
{
  int getDays();
}
{
  int days;
  cout << "Enter total of days you'll be staying: ";
  cin >> days;
  if (days < 0)
  cout << "Days cannot be less than 0 \n\n"
       << "Enter total of days you'll be staying again: \n";
  cin >> days;
}

//Bullet 2
  double dTime = getDepartureTime();
{
  double getDepartureTime();
}
{
  cout << "Enter your departure time: ";
  cin >> dTime;
  if (dTime < 0)
{
  cout << "Time cannot be less than 0 \n"
       << "Enter departure time again: \n";
  cin >> dTime;
}
  else if (dTime > 24)
{
  cout << "Time cannot exceed more than 24 hours \n"
       << "Enter departure time again: \n";
  cin >> dTime;
}
}

This code going to be divided into separate functions and from the looks of it i might be messing up. The code that i have should be in a seperate function outside of int main but i'm not sure if doing this correctly cause i'm new to this function stuff and the book i have is showing bad examples of how to structure this function.

  • What is your question? Your code is very odd. You might want to read about some of the basics again. – Retired Ninja Feb 11 '15 at 07:40
  • http://www.cplusplus.com/doc/tutorial/functions/. – rubikonx9 Feb 11 '15 at 07:40
  • You try reading about classes and member functions, by the look of your code, grouping the similar functions in a class will better suite your needs. example, create class for expense, fee, time, allowance, and create getter and setter function. – Sridhar Nagarajan Feb 11 '15 at 07:57
  • its a group project with 4 other people. What i did is in bullet 1 and 2 while the other stuff is what someone else did. – Toxic0verdose Feb 11 '15 at 08:03
  • " i'm new to this function stuff and the book i have is showing bad examples" - get another book? Even if this is a course book, forced upon you, you can still read others. See http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list and https://github.com/vhf/free-programming-books/blob/master/free-programming-books.md (there’s your fish ;-) – Mawg says reinstate Monica Feb 11 '15 at 09:43

2 Answers2

1

Is this what you're looking for?

Say the 'getdays' function; it should be defined like this:

int getDays(){
    int days;
    cout << "Enter total of days you'll be staying: ";
    cin >> days;
    if (days < 0)cout << "Days cannot be less than 0 \n\n"<< "Enter total of days you'll be staying again: \n";
    cin >> days;
    return days;
}

and in int main you can just have int days=getDays(). So when you cout << days you should get...whatever the user entered.

Hope it helps!

acenturyandabit
  • 1,188
  • 10
  • 24
0

Below implementation has been done only for “int getDays()”. You have to modify all those methods in this way.

#include <iostream>
#include <iomanip>
using namespace std;

//Function prototypes
struct HotelMenu
{
    HotelMenu()
    {
        MILES = 0.27; //Expense per miles driven
        PARKING = 6; //Allowed daily parking allowance
        TAXI = 10; //Allowed daily taxi allowance
        HOTEL = 90; //Allowed nightly hotel allowance
        BKFST = 9; //Allowed daily breakfast allowance
        LUNCH = 12; //Allowed daily lunch allowance
        DINNER = 16; // ALlowed daily dinner allowance
    }
    int getDays();
    double getDepartureTime();
    double getArrivalTime();
    double getAirfareFees();
    double getRentalFees();
    int getMileageFees();
    double getParkingFees(int days);
    double getTaxiFees(int days);
    double getRegistrationFees();
    double getHotelExpenses(int days);
    double getBreakfastExpenses(int days, double dTime, double aTime);
    double getLunchExpenses(int days, double dTime, double aTime);
    double getDinnerExpenses(int days, double dTime, double aTime);

  private:
    //Global constants
    const double MILES;
    const int PARKING;
    const int TAXI;
    const int HOTEL;
    const int BKFST;
    const int LUNCH;
    const int DINNER;
}

int HotelMenu::getDays()
{
    int days;
    cout << "Enter total of days you'll be staying: ";
    cin >> days;
    if (days < 0)
    cout << "Days cannot be less than 0 \n\n"
        << "Enter total of days you'll be staying again: \n";
    cin >> days;

    return days;
}

double HotelMenu::getDepartureTime()
{
    double dTime;
    cout << "Enter your departure time: ";
    cin >> dTime;
    if (dTime < 0)
    {
        cout << "Time cannot be less than 0 \n"
            << "Enter departure time again: \n";
        cin >> dTime;
    }
      else if (dTime > 24)
    {
        cout << "Time cannot exceed more than 24 hours \n"
           << "Enter departure time again: \n";
        cin >> dTime;
    }
    return dTime;
}

int main()
{
    //Variable Declaration
    double grandTotal = 0, //Total expenses incurred
        allowedTotal = 0, //Total allowable expenses for the trip
        reimburseTotal = 0, //Excess that must be reimbursed, if any
        savedTotal = 0, //Amount saved, if any
        mealExpenses; //Total cost incurred for meals

    // Create an instance of the structure
    HotelMenu aInstance;

    //Input & function processing

    //Bullet 1
    int days = aInstance.getDays();

    //Bullet 2
    double dTime = aInstance.getDepartureTime();
}

Hope it helps !!

Rabinarayan Sahu
  • 156
  • 1
  • 1
  • 7