Thread: C++ Project

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    8

    Question C++ Project Help Needed

    I have to do a program for a class and I am clueless.

    I have to write a C/C++ program for an amusement park that encourages family visits. The pricing schedule is as follows:

    Category Price

    Children under 8 $ 2.00 each

    Youth 8 - 18 $ 8.50 each (for every 4 tickets in this age group,
    one person is free; this means for every four tickets purchased, the 4th ticket is free.)

    Adults 19+ $12.50 each (after 10 adult tickets, the price is $9.00 the first 10 tickets are always $12.50)


    All groups with 20 or more people must pay a $25.00 security fee.

    Write a program that accepts the number of people in each of the three age categories, performs the necessary computations, and displays a bill for the group's admission similar to the display below. Display the number of tickets and the cost of admission for each category, total number of tickets, and the total cost. Only display the security fee if not zero. Be sure to test for a variety of values.

    Set up constants as necessary.

    Attached is the code I have written so far. I have the basics down but can't get the necessary mathmeatical operations down.

    If someone could take a look and give me suggestions I would greatly appreciate it.
    Last edited by Rhino1775; 10-16-2003 at 12:52 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    > All groups with 20 or more people must pay a $25.00 security fee.
    Well all you add now is a bunch of rules to the code, something like this
    Code:
    if ( (child + youth + adult) >= 20 ) {
        security_fee = 25;
    } else {
        security_fee = 0;
    }
    Now work out what child_fee (easy),youth_fee and adult_fee should be, then output the grand total

    Code:
    cout << "please pay " << child_fee + youth_fee + adult_fee + security_fee;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    8

    Question C++ Project Help Needed

    I have to do a program for a class and I am clueless.

    I have to write a C/C++ program for an amusement park that encourages family visits. The pricing schedule is as follows:

    Category Price

    Children under 8 $ 2.00 each

    Youth 8 - 18 $ 8.50 each (for every 4 tickets in this age group,
    one person is free; this means for every four tickets purchased, the 4th ticket is free.)

    Adults 19+ $12.50 each (after 10 adult tickets, the price is $9.00 the first 10 tickets are always $12.50)


    All groups with 20 or more people must pay a $25.00 security fee.

    Write a program that accepts the number of people in each of the three age categories, performs the necessary computations, and displays a bill for the group's admission similar to the display below. Display the number of tickets and the cost of admission for each category, total number of tickets, and the total cost. Only display the security fee if not zero. Be sure to test for a variety of values.

    Set up constants as necessary.

    Attached is the code I have written so far. I have the basics down but can't get the necessary mathmeatical operations down.

    If someone could take a look and give me suggestions I would greatly appreciate it.

  4. #4
    Registered User
    Join Date
    Oct 2003
    Posts
    8

    C++ Project Help Needed

    Below is attachement with work I have so far

  5. #5
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    I'm not exactly sure what you want us to do here. I lookedat your code, and there is really not much there. What have you learned so far? did you learn about functions? classes? if you have learned about functions I would make each set of calculations/displays have its own function. Don't use any globals, and use <iostream> instead of <iostream.h>.

    axon

    EDIT::I just noticed that you main() is accepting arguments? your assignment description does not talk about accepting any command lines arguments, so why do you have it? is there anything else you must do? any flags?
    Last edited by axon; 10-16-2003 at 01:24 PM.

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Reposting your question without any effort on your part will not help your case.
    Threads merged
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Wen Resu
    Join Date
    May 2003
    Posts
    219
    I made some additions and comments. i sugegst you look at what i did so you know how to do it
    Code:
    // Don Salzler
    // Proj2.cpp
    // Program for calculating cost of visitors to amusement park
    // CodeWarrior
     
    #include <iostream>
    using namespace std;
    // This function simply calculates the total cost for children
    float CalcChild(int NumChild) {
         return  NumChild * 2;
         }
    // This function calculates the total number of free Youths and figures cost based on that
    float CalcYouth(int NumYouth) {
          int DivFour = NumYouth / 4;
          return  (NumYouth - DivFour) * 8.50;
          }
    //This function calculates cost  if family has in excess of 10 adults, if if they dont't
    float CalcAdult(int NumAdult) {
          float Total;
          if (NumAdult > 10) {
             Total = ((NumAdult - 10) * 9) + 125;
             }
          else {
          Total = NumAdult * 12.50;
          }
          return Total;
          }
    
    int main(int argc, char* argv[])
    {
     int child, youth, adult;
     char any;
     
     const double CHILDPR = 2.00;
     const float YOUTHPR = 8.50;
     const float ADULTPR = 12.50;
     float CostChild, CostYouth, CostAdult;
     cout <<"                       Don's Amusement Ticket Entry\n";
     cout <<"                       ------------------------------\n\n";
     cout <<"                     Enter number of children under 8: ";
     cin >> child;
     cout <<"                     Enter number of youth 8-18:       ";
     cin >> youth;
     cout <<"                     Enter number of adults:           ";
     cin >> adult;
     
     cout <<""<<endl <<endl <<endl;
     // Calculating each cost
     CostChild = CalcChild(child);
     CostYouth = CalcYouth(youth);
     CostAdult = CalcAdult(adult);
    
     
     cout <<"                           Don's Amusement Park\n\n";
     cout <<"          Category            Tickets         Price          Total\n";
     cout <<"          --------            -------         -----          -----\n";
     cout <<"          Children Under 8       "<<child <<"            $2.00" <<"          $" <<CostChild<<endl;
     cout <<"          Youth 8-18             "<<youth <<"            $8.50*"  "         $" <<CostYouth <<endl;
     cout <<"          Adults 19+             "<<adult <<"            $12.50**""       $" <<CostAdult <<endl;
     cout <<"                              -------\n";
     cout <<"                                 " <<child+youth+adult <<endl;
     cout <<"                                                             -----\n";
     if (child + youth + adult >= 20){    // in event theres20 or more poeple
     cout <<"                              Total Bill:   " <<"                 $" <<CostChild + CostYouth + CostAdult + 25<<"***" <<endl <<endl;
     }
     else {  // otherwise
     cout <<"                              Total Bill:   " <<"                 $" <<CostChild + CostYouth + CostAdult <<endl <<endl;
    
     }
    cout <<"          *One person is free for every 4 tickets in this age group\n";
     cout <<"        **The price is $9 per adult in excess of 10 adults\n";
     if (child + youth + adult >= 20){ // Gota let em know about the fee
     cout<<"        ***A $25 security fee has been attached as you have 20 or more people\n";
     }
           
     cin >> any;
        return 0; 
     
    }

  8. #8
    Registered User
    Join Date
    Oct 2003
    Posts
    8

    Thanks Iamien!

    Thanks Iamien! That is a huge help. I do understand it now after looking at the solution. I have been working on this for quite awile and just ran into a brick wall.

    It is an online course I am taking so it is very difficult to work through problems if there isn;t anyone to actually show me what I am doing incorrectly.

    Thanks again!!

  9. #9
    Registered User PotitKing's Avatar
    Join Date
    Dec 2001
    Posts
    28
    Instead of actually having to type those whitespaces

    like:
    cout << " hi ";
    then use tabs

    cout << "\thi\t":

    % gcc -v
    Configured with: FreeBSD/i386 system compiler
    Thread model: posix
    gcc version 3.3.3 [FreeBSD] 20031106

  10. #10
    Wen Resu
    Join Date
    May 2003
    Posts
    219
    No problem. if you have any questions just ask. Make sure you know how to set up functions

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 09:05 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  3. Dynamic Binding
    By gpr1me in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2006, 09:01 AM
  4. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM