I am having a hard time getting started on this array. I am in a C++ class but I have no refrence material to go off of This is what i have so far, The purpose of the code is to find out how many wait staff is needed if you have 24 customers...for example for 0 customers you need 3 wait staff. I am not trying to get some one to do my homework I am just lost and cannot get a hold of my instructor

#include <iostream>
using namespace std;
void main()
{
   int customers [24] = {1, 2, 3, 4, 5, 6,
                                  7, 8, 9, 10, 11, 12
                                  13, 14, 15, 16, 17, 18
                                  19, 20, 21, 22, 23, 24};

Recommended Answers

All 21 Replies

Programs don't write themselves. You need to have some sort of a plan before you can do anything. You have successfully created an array of 24 ints, assuming the closing curly brace was intentionally left off of your snippet for the purposes of you post or unintentionally snippet by the software the board using to display the post. What an array of 24 ints has to do with your project, however, is unknown. I assume there is some sort of formula that someone has provided you to iuse in the program (otherwise it becomes a random guess), but heaven only knows what it might be based on your post.

BTW the return type for main() is int, not void. Using type void is not portable and requires an extra keystroke to write so don't use it.

ok thank you, so use intinstead of main? my instructor has use void all of the time. I'm currently trying to figure out a templeate for this so I can get the info in there the me problem is, is that we have a problem solving book and not a c++ book. Thank you for your help

Yeah my post was a little vague, we have to create a program that figures out how many wait staff is needed based on the number of customers come in to the store using an array and a for loop

>>my instructor has use void all of the time.
I'm sorry to hear that.

>>I'm currently trying to figure out a templeate for this so I can get the info in there

I assume from this statement that you are trying fo fill an array with data, though I can't be sure of that from the above comment. If I'm correct in my assumption, then there are three (routine) ways to enter data into an array. 1) You can hard code it during initialization, like your original post did. 2) You can have the user enter data using standard input. Or, 3) you can read input in "automatically" from some other source, often from a file.

here is what I have come with thus far. Im not sure if this is going to help you help me though cause Im confusing myself. LOL

        int customers [24] = {1, 2, 3, 4, 5, 6,
                              7, 8, 9, 10, 11, 12
                              13, 14, 15, 16, 17, 18
                              19, 20, 21, 22, 23, 24};


       Char total_customers

        cout << "how many customers?: " << total << endl;
        break;

    case:               
        total_customers = 0;
        for (c=0; w<=9)

Char isn't a native type to C++, though char is. Since the syntax in C++ is case sensitive Char and char are not the same.

break and case are keywords in C++. They are often used in combination within a switch statement, though I can't tell if that's what you are trying to write or not.

In the following line:

total_customers = 0;

0 is an int, and I believe you want total_customers to be of type char. Since type char in C++ is a user friendly format for using ints to represent printable characters, the above would be a legal statement, but I don't think it is what you wanted to do, since it is assigning the null char to total_customers.

I still don't see how the material you posted in your last post relates to the problem at hand, though. What formula do you have to prevent the decision to determine how many waiters are needed from being a complete guess and what relevance to that process is an array of 24 ints?

yeah I figured something wasen' t right there, The way he explained an array to us was that when you set it up you have to put in the number of spaces needed in memory which is probably the only part I have been able to do for sure at this point.. Then he said the program needs to run to give us the number of wait staff needed in the assignment he gave us these numbers
For 0 customers you still need 3 employees.
For 10 customers you need 4 employees.
For 19 customers you need 4 employees.
For 20 customers you need 4 employees.
For 25 customers you need 5 employees

This is what I was trying to do In that last snippit I posted was set up the loop to run but it's not going to work unless I identify all of these numbers, is that correct?

here is what i just came up with I know it is probably missing some stuff but does this even look right in any way? Thank you by the way for your help I really appreciate it

#include <iostream>
using namespace std;
void main()
{
        int customers [24] = {1, 2, 3, 4, 5, 6,
                                  7, 8, 9, 10, 11, 12
                                  13, 14, 15, 16, 17, 18
                                  19, 20, 21, 22, 23, 24, 25};

        int total_customers, Wait_staff, c,w;

            cout << "how many customers?: " << total << endl;
            break;

        case:               
            total_customers = 0;
            for (c < = 9; w = 3;)
            {
                for (c < = 24; w = 4;)
                {
                    for (c = 25; w = 5;)    ;
                }
            }

I did not put those faces in there

here is exactly what he wants us to do

Use an array to represent the number of customers each hour. Don’t calculate the average number of customers – assume that has been done and you know the average for each hour of the day.

I suppose you could jury rig the program to use an array, but it isn't really necessary. It is most easily accomplished by using a sequence of if/else statements:

if the number of customesrs is 0
  then number of waiters needed is 3;
else if number of Customers  is more than 0 and the number of customers  is than or equal to a
  then number of waiters needed is 4;
else if number of customers more than a and the number of custormers is less than b   
   then the number of waiters is 5
etc

where a < b, etc.

Then use a loop to ask for user input into the number of customers present, use that value to determine the number waiters to have using something like the above protocol, an print out the number of waiters needed to service the number of customers present. The loop allows the user to enter as many variatons as they want. How you write the loop is up to you, and whether you want to do any input validation is up to you, etc.

If the number of customers per hour is held in an array, fine. That information can be used to control how many times the loop I described above is run and you don't need to ask for user input each time through the loop since you will use the information within the array instead. You will still need some souce for the data in the array as I discussed earlier.

ok I got a hold of a person that is my class who is also having a problem and he sent me this

The process of calculating the number of employees needed is to divide the number of customers by 20, then add the 3 permanent employees. Use integer division to get a whole number. HINT: integer division for 19 customers gives a different answer than for 20 customers, but the number of employees is the same. How do you handle the “exception” to the calculation? (Think modulus division)

here is what I have come with thus far.... Im confusing myself. LOL
Char total_customers

cout << "how many customers?: " << total << endl;
break;

case:
total_customers = 0;
for (c=0; w<=9)

roc a, do you know what you are doing? No offense intended but as I can see, it seems you don't know what you are writing. Explaining your knowledge level will help people know how to help you better

ok I see so I was kind of close with what I have done so far....yeah I guess we come up with our own numbers

evstevemd, actually no i don't I have been taking this class for a couple of weeks but thats it, as i was saying before the schools dosen't even give us a C++ book

A formula for calculating the number of employees needed is found. You can use it instead of a series of if/else statements to determine how many empolyees are needed.

number of employees needed is 3 + (number of customers divided by 20)

though I don't see what the hint about an exception and the use of the modulo operator is about.

You still need to determine how many times you want to run the loop to apply the formula. It could be an open ended program that can run as long as the user enters data or it could be a predetermined number of cases to be evaluated stored in a container someplace, like in an array.

thank you guys very much for all of you help it is greatly appreciated, you have been way more helpful and informative than the class i am taking.

evstevemd, thank you for the links

evstevemd, thank you for the links

You are welcome :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.