Hey, I'm wondering if this is possible. I store customers in an array:

string customer[10];
customer[1] = "Phil";

But I have a menu, that has things like
1. Display customers
2. Add customers
The thing I want to do is not show the 'Display customers' if there has been no customers entered. For example

if customers 
then
    // display the full menu
otherwise
   // only display add customer
end if

Any ideas?

Hey, I'm wondering if this is possible. I store customers in an array:

string customer[10];
customer[1] = "Phil";

But I have a menu, that has things like
1. Display customers
2. Add customers
The thing I want to do is not show the 'Display customers' if there has been no customers entered. For example

if customers 
then
    // display the full menu
otherwise
   // only display add customer
end if

Any ideas?

You need to check if the array is empty or not for your condition you got there.

The way I'd do that is by creating another member variable of type int, let's say:

int size = 0;

if customer[0] != " " then //if the first array index is not empty
for (int i=0; i<size; i++) //from first index to last added entry
cout customer of i //print the current array index value
else 
cout enter a new customer name
cin cutomer name
customer[size++]=cutomer name

You will need another string for customer name. Obviously I gave you an algorithm and not the actual code. ;) Good luck.

If the array of customers may hold less than the maximal number of possible customers then you should keep track of the actual number of customers anyway. Under that scenario you can evalute the actual number of customers. If it's zero, then display menu A and if it isn't, then display menu B.

string customer[10];
customer[1] = "Phil";

If you wanted here to access the first element of the array so you have to use this:

customer[0] = "Phil";

You can use something like this to check if the first element of the array is empty, so that if it's empty it means that no customers have been entered:

if (customer[0].begin()==customer[0].end())
//only display "Add Customers".
else //display all the menu

Hope that helped,,,
Kimo :icon_smile:

Use vectors of string.

vector< string > customers; //size == 0
//do stuff

//menu stuff;
if(!customers.empty() )
   cout <<  "Display Members ? \n";
//other menu stuff

To add customers, you can use the push_back method of vectors;

vector< string > customers;
customers.push_back("Phil");
customers.push_back("Tyler");

Here is some reference

Use vectors of string.

vector< string > customers; //size == 0
//do stuff

//menu stuff;
if(!customers.empty() )
   cout <<  "Display Members ? \n";
//other menu stuff

To add customers, you can use the push_back method of vectors;

vector< string > customers;
customers.push_back("Phil");
customers.push_back("Tyler");

Here is some reference

I agree with you because it's more simple to use vectors or deques.
But i think he wants to know how to do that with an array, not just to solve a problem :icon_cheesygrin:

,,,
Kimo

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.