# An Event Planner

• August 2nd, 2013, 06:11 PM
rockx
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;     }```
• August 2nd, 2013, 08:37 PM
GCDEF
Re: An Event Planner
Quote:

Originally Posted by rockx
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.
• August 2nd, 2013, 09:09 PM
rockx
Re: An Event Planner
GCDEF, could you help me please
• August 3rd, 2013, 06:55 AM
GCDEF
Re: An Event Planner
Quote:

Originally Posted by rockx
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.
• August 3rd, 2013, 07:28 AM
2kaud
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++/
• August 3rd, 2013, 05:31 PM
rockx
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.
• August 3rd, 2013, 05:47 PM
GCDEF
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.
• August 3rd, 2013, 11:54 PM
rockx
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......
• August 4th, 2013, 06:23 AM
2kaud
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.