Thread: Need help coming up with an answer

  1. #1
    Registered User
    Join Date
    Sep 2013
    Posts
    2

    Need help coming up with an answer

    Hello, I pretty much have my entire assignment finished, however I'm stumped on how to actually solve this one. Can someone please walk me through how to make a working function for what is asked? Thanks


    Ex.

    Assume that a full hotel room houses 4 people and costs $100 per night. For smaller hotel rooms, there's a per person charge of $30. (Thus, for a family of 10, two full rooms would fit 8 people, costing $200/night and a third room would have 2 people, costing $60/night for a grand total of $260/night for the family.)

    Input Specs:
    The first two values will be positive integers while the last will be a positive real number less than 20.

    How it will run:

    How many people are in the family?
    5
    How many days will your family be on vacation?
    3
    What is the sales tax percentage in the vacation locale?
    6.5
    Your family will spend $415.35 for lodging on your vacation.

  2. #2
    Registered User
    Join Date
    Sep 2013
    Posts
    2
    Quote Originally Posted by burnsidex View Post
    Hello, I pretty much have my entire assignment finished, however I'm stumped on how to actually solve this one. Can someone please walk me through how to make a working function for what is asked? Thanks


    Ex.

    Assume that a full hotel room houses 4 people and costs $100 per night. For smaller hotel rooms, there's a per person charge of $30. (Thus, for a family of 10, two full rooms would fit 8 people, costing $200/night and a third room would have 2 people, costing $60/night for a grand total of $260/night for the family.)

    Input Specs:
    The first two values will be positive integers while the last will be a positive real number less than 20.

    How it will run:

    How many people are in the family?
    5
    How many days will your family be on vacation?
    3
    What is the sales tax percentage in the vacation locale?
    6.5
    Your family will spend $415.35 for lodging on your vacation.


    Honestly I just need help with the math part, I'm not sure how to exactly figure out how to get the rates.

  3. #3
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    You need to first figure out how many 4-person groups there are.
    Each group of 4 is $100 per day.
    Each person left over cost $30 per day.
    Multiply that total by the number of days.
    Then multiply that by the tax rate.

    So for the example of 5 people for 3 days and 6.5% tax:
    1 group of 4: $100
    1 single: $30
    Total: $130

    Times 3 days is $390

    Times 1.065 for sales tax is $415.35

    Use integer division to calculate how many groups of 4 there are and the modulus operator % to calculate how many are left over:
    Code:
    int numGroups, numSingles;
    ...
    numGroups = numPeople / 4;
    numSingles = numPeople % 4;
    That should get you started. Give it a go and post some code. You don't have to do the whole program at once. Start with the input and the above calculations and print numGroups and numSingles to see if it's correct.
    Last edited by oogabooga; 09-02-2013 at 09:49 PM.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 08-13-2012, 03:19 AM
  2. Help with comparing answer to math problem and user's answer
    By Jake Garbelotti in forum C Programming
    Replies: 6
    Last Post: 07-20-2012, 10:12 PM
  3. my second coming
    By thestien in forum Game Programming
    Replies: 6
    Last Post: 12-17-2007, 09:54 AM
  4. Volume always coming 0
    By SVXX in forum C++ Programming
    Replies: 21
    Last Post: 10-04-2007, 07:47 AM