I am trying to write a program with two separate arrays in it. In the first array I will store all my Dads clients names. In the second array I will store all their address. If I wanted to do this how would I go about storing the arrays so that when I display them later in the program they display in alphabetical order.
I know how to make the arrays, but I do not no how to store them or display them in alphabetical order

I am also going to make the arrays [20] each but if there are less then 20 clients being entered i would like to be able to stop the loop when the user enters a certain key term such as "stop" Would i be able to do this with an if statement. If name = 'stop' break. Or something like that.

I am new to c++ and i'm trying so thanks so much for any help

So the problem is in sorting the arrays? Look into this - http://www.cplusplus.com/reference/algorithm/sort.html It's the standard sorting method. The example there is numerical but I'm certain it does alphabetical data too.

>> if there are less then 20 clients being entered i would like to be able to stop the loop when the user enters a certain key term such as "stop"
>> If name = 'stop'
It depends on the type of name. If it's std::string then you can indeed do the above (but with " rather than '). But if it's a c-style string you're going to have to use strcmp(). Look them both up in the aforementioned site.
You have you array, right. So what you could do is loop for an undefined number of times and read in a value into a secondary variable. Test this variable agains break values. If it is one (eg if it's "stop", as above), break from the loop. You should look into dynamic array allocation and after that vectors or maybe (linked) list or something.

umm...I really didn't understand any of that stuff that i read here is the code i have so far

#include <iostream>
#include <string>
#include <math.h>
using namespace std;


int main()
{
const int ATIME = 20;
string studentNames[ATIME];
int scores[ATIME];



for (int i = 0; i < ATIME ; i++)
{
cout << "Enter student name: " << endl;
cin >> studentNames;
cout << "Enter score: " << endl;
cin >> scores;
if (studentNames = "stop";)
{
break;
}
}
cout << "break worked";


return 0;
}

i am trying to figure out how to get that to break but it keeps giving me an error

any ideas?

>> studentNames = "stop"
studentNames=="stop"

Use code tags! [code] PUT YOUR CODE BETWEEN THESE [/code]

Error 1 error C2446: '==' : no conversion from 'const char *' to 'std::string *' c:\documents and settings\kyle\desktop\purdue\fall 2007\cit 267\lab assignments\lab06\lab06.cpp 26


This is the error i get when i do
if (studentNames == "stop")
{
break;
}

does anyone know why?

Sorry. My bad. Student names is a std::string array, right? Do the test on the specific element you're talking about? So:

if (studentNames[i] == "stop" ) 
    {
      break;
    }

In that case.

twomers,

thanks for your help.

Look into saving and loading to and from a file too. it might be useful.

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.