An Event Planner
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: An Event Planner

  1. #1
    Join Date
    May 2004
    Posts
    202

    An Event Planner

    Hey guys i m trying to do an assignment that was posted about 10-15years ago. but i m doing it with a slight bit of modification. Below is the detail of the assignment.

    http://www.taumoda.com/web/class/day6.html


    What i am trying to do is, instead of it being a kids b'day party, let it be a normal adults party.

    Let there be x number of invited guests. and lets imagine that 50% of all the guest consumer beer. and let beer come in kegs to feed 20 guests/keg.

    I just need help with the last function in my code. where i want the number of invited guest to come from an earlier function (inv_guest) and then calculate the number of kegs of beer to be ordered. for example, if 123 people are invited, a total of 4 kegs of beer will be ordered; 3 for the first 60 and an extra 1 for the remaining 1 person.

    Code:
    #include <iostream>
    #include <stdlib.h>
    using namespace std;
    
    const int kegs = 20;
    const int cases = 20;
    const int pizza = 4;
    int num_guest = 0;
    
    void welcome();
    int inv_guest(int);
    void display();
    void input();
    void beer(int &);
    void coke();
    int main ()
    {
        int x, choice;
        
       
       /* 
        while (choice!=6)
        {
         switch(choice)
    */
        input();
        
        
        beer(num_guest);
     
     
     
     system("PAUSE");
     return 0;   
    };
    
    void input()
    {
    
         int choice;
         welcome();  
    do 
    {
       
       cout<<"\n\nEnter A Valid Choice \n";
       cin>>choice;
    }while(!(choice>=1 && choice<=5));
    
    }
    
    int inv_guest(int num_guest)
    {
        int guest;
        
        cin >> guest;
     return guest;   
    }
    
    void welcome()
    {
              cout << "\t***The Party Planning Assistant is please to be at your service!***\n\n";
              cout<<"\n*********************************\n";
              cout<<" 1. Enter number of Invited Guests \n";
              cout<<" 2. Determine beverage orders \n";
              cout<<" 3. Determine food orders \n";
              cout<<" 4. Display Information \n";
              cout<<" 5. Exit Application \n";
              cout<<"***********************************"; 
     
         
    }
    void beer(int &people)
    {
         double beer = 0;
         people *= inv_guest(people);;
        // inv_guest(people);
         beer = people/2;
         beer = beer/kegs
         cout << "\n\n Number of kegs =" << kegs;
         
    }

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    11,980

    Re: An Event Planner

    Quote Originally Posted by rockx View Post
    Hey guys i m trying to do an assignment that was posted about 10-15years ago. but i m doing it with a slight bit of modification. Below is the detail of the assignment.

    http://www.taumoda.com/web/class/day6.html


    What i am trying to do is, instead of it being a kids b'day party, let it be a normal adults party.

    Let there be x number of invited guests. and lets imagine that 50% of all the guest consumer beer. and let beer come in kegs to feed 20 guests/keg.

    I just need help with the last function in my code. where i want the number of invited guest to come from an earlier function (inv_guest) and then calculate the number of kegs of beer to be ordered. for example, if 123 people are invited, a total of 4 kegs of beer will be ordered; 3 for the first 60 and an extra 1 for the remaining 1 person.

    Code:
    #include <iostream>
    #include <stdlib.h>
    using namespace std;
    
    const int kegs = 20;
    const int cases = 20;
    const int pizza = 4;
    int num_guest = 0;
    
    void welcome();
    int inv_guest(int);
    void display();
    void input();
    void beer(int &);
    void coke();
    int main ()
    {
        int x, choice;
        
       
       /* 
        while (choice!=6)
        {
         switch(choice)
    */
        input();
        
        
        beer(num_guest);
     
     
     
     system("PAUSE");
     return 0;   
    };
    
    void input()
    {
    
         int choice;
         welcome();  
    do 
    {
       
       cout<<"\n\nEnter A Valid Choice \n";
       cin>>choice;
    }while(!(choice>=1 && choice<=5));
    
    }
    
    int inv_guest(int num_guest)
    {
        int guest;
        
        cin >> guest;
     return guest;   
    }
    
    void welcome()
    {
              cout << "\t***The Party Planning Assistant is please to be at your service!***\n\n";
              cout<<"\n*********************************\n";
              cout<<" 1. Enter number of Invited Guests \n";
              cout<<" 2. Determine beverage orders \n";
              cout<<" 3. Determine food orders \n";
              cout<<" 4. Display Information \n";
              cout<<" 5. Exit Application \n";
              cout<<"***********************************"; 
     
         
    }
    void beer(int &people)
    {
         double beer = 0;
         people *= inv_guest(people);;
        // inv_guest(people);
         beer = people/2;
         beer = beer/kegs
         cout << "\n\n Number of kegs =" << kegs;
         
    }
    Your code is pretty confused. Take it one step at a time.

    First, don't name a variable the same as a function. You'll confuse yourself.

    You're calling beer with an int reference called people that's set to 0. Why, isn't clear. Then you're passing people as a parameter to inv_guest, but never using it in that function. Then you multiply people (which is still set to 0, but the value returned by inv_guest, which doesn't make any sense.

    It looks like you're guessing, or randomly coding without having a plan. Work out what steps you need to take before you try to write the code.

  3. #3
    Join Date
    May 2004
    Posts
    202

    Re: An Event Planner

    GCDEF, could you help me please

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    11,980

    Re: An Event Planner

    Quote Originally Posted by rockx View Post
    GCDEF, could you help me please
    I thought I did. I pointed out some places where you're going astray, but I can't give you the understanding that you lack. Go back and read the chapters on the basics in whatever book you're using and learn about functions, passing arguments to functions and declaring variable. You're missing some fundamentals that you need to understand.

  5. #5
    Join Date
    Dec 2012
    Location
    England
    Posts
    1,995

    Re: An Event Planner

    As GCDEF stated, this looks exactly like code that has been made up 'on the hoof' as you go along. You really, really can't write programs like this. Not even us 'gurus' that have been coding since just about when computers were invented don't just sit down and 'write' a program. We first design the program. Determine what output is required, what input is necessary, what processing has to be undertaken. What is the high-level program 'flow'. What functions are required and their purpose, what parameters are required for these functions, what values do they return. For c++ programs, what objects are referenced by the program, how these objects are to represented as classes, what operations are required for the objects etc etc etc. When and only when all this design work has been undertaken do we then start to code the program from the design.

    I would strongly suggest that before you code further that you first produce a design for the program. Once you have the design that you are happy with then code your program from the design. You know then how the program is supposed to work (as you have the design) so if you have issues with writing the code we can provide guidance. If (when!) your progam doesn't work first time you can then debug your code against the design to see where its behavior deviates from that expected.

    You might find these web sites of interest
    http://www.learncpp.com/
    http://www.cplusplus.com/doc/tutorial/
    http://programminghelp.org/c++/
    Last edited by 2kaud; August 3rd, 2013 at 10:49 AM.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  6. #6
    Join Date
    May 2004
    Posts
    202

    Re: An Event Planner

    hey guys. thanks a lot for commenting. yes i was kinda coding off the hoof, but now i have gripped my reins.

    here is my new code:

    Code:
    #include <iostream>
    #include <stdlib.h>
    #include <cmath>
    using namespace std;
    
    
    //Declaration of Global Constants.
    const int kegs = 20;
    const int cases = 20;
    const int pizza = 4;
    int num_guest = 0;
    
    //declaring the functions
    void welcome();
    int inv_guest(int);
    void display();
    int input();
    int beer_cal(int);
    
    int main()
    {
    
    	int choice, guest, beer_keg;
       // int beer;
    
    	welcome();  
    	input();
    	guest = inv_guest(num_guest);
    
    //	choice = input();
    
        beer_keg = beer_cal(guest);
    
    	cout << "Kegs = " << beer_keg;
    
    	system("PAUSE");
    	return 0;
    }
    
    void welcome()
    {
              cout << "\t***The Party Planning Assistant is please to be at your service!***\n\n";     
              cout<<"\n*********************************\n";
              cout<<" 1. Enter number of Invited Guests \n";
              cout<<" 2. Determine beverage orders \n";
              cout<<" 3. Determine food orders \n";
              cout<<" 4. Display Information \n";
              cout<<" 5. Exit Application \n";
              cout<<"***********************************"; 
     
         
    }
    int input()
    {
    
         int choice;
        
    do 
    {
       
       cout<<"\n\nEnter A Valid Choice: ";
       cin>>choice;
    }while(!(choice>=1 && choice<=5));
    
    return choice;
    }
    int inv_guest(int num_guest)
    {
        int guest;
        cout << "\nPlease enter the number of invited guests: ";
        cin >> guest;
    return guest;   
    }
    
    int beer_cal(int people)
    {
         double beer_keg = 0;
         int beer;
         
         beer = (people/2);
         beer_keg = beer/kegs;
        // cout << "\n\n Number of kegs =" << beer << endl << endl;
         return beer_keg;
    }
    I just need help with the last function in my code. where i want the number of invited guest to come from an earlier function (inv_guest) and then calculate the number of kegs of beer to be ordered. for example, if 123 people are invited, a total of 4 kegs of beer will be ordered; 3 for the first 60 and an extra 1 for the remaining 1 person.

  7. #7
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    11,980

    Re: An Event Planner

    You're close. The missing piece is adding 1 to the number of kegs if the number of people isn't divisible by 20. You can use the modulus operator (%) to determine that.

  8. #8
    Join Date
    May 2004
    Posts
    202

    Re: An Event Planner

    I think i got it

    Code:
    int beer_cal(int people)
    {
         int beer_keg = 0; 
    	 int beer = 0;
         
         
         beer = (people/2);
         beer_keg = beer/kegs;
         if ( beer_keg % 20 == 0 )
    	 {
         return beer_keg;
    	 }
    	 else 
    	 {
    	 return beer_keg +1;
    	 }
    }
    but now i m stuck with my main......

  9. #9
    Join Date
    Dec 2012
    Location
    England
    Posts
    1,995

    Re: An Event Planner

    Your beer_cal function can be simplified to

    Code:
    int beer_cal(int people)
    {
    	return (int)ceill(people / 2.0 / kegs);
    }
    What guidance do you want for main?

    Note also that the while statement in your input function can also be simplifed to

    } while (choice < 1 || choice > 5);

    Also, you don't need the global variable num_guest as you are passing the number of guests as a parameter to beer_cal. invite_guest doesn't need a parameter as it returns the number of guests.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center