so i'm trying to fix my "load" function, but i can't seem to get it to work correctly.
here's the load function i have currently:
void load(string messages[], int keys[], int& numElements)
{
int index = 0;
int key;
string message;
while(index < MAX_SIZE && key > 0)
{
cout << "Please enter a key for number " << (index + 1) << ":\n";
cin >> key;
cout << "Please enter a message for number " << (index + 1) << ":\n";
getline(cin, message);
if(key > 0)
{
addMessage(messages, keys, numElements, message, key);
index++;
}
}
numElements = index;
}
so what needs to happen is, i'm supposed to prompt the user for a key and message (which will be stored in their corresponding array). the program is supposed to keep asking for a key and message until a negative key value is entered. within the load function i'm supposed to call the addMessage function to add the key/message pairs to their arrays.
here's the addMessage function:
void addMessage(string messages[], int keys[], int numElements, string message, int key)
{
//this function takes in a message and one key, adds them to an array of message and keys
//and adds to keep track of how many elements are currently being stored. if it is full it
//outputs an error message.
if(!isFull(numElements))
{
messages[numElements]=message;
keys[numElements]=key;
numElements++;
}
else
{
cout << "error, not enough space\n";
}
}
when i run the program the load function asks for a key, but won't let me enter a message. i can't figure out what the issue is. i also think i'm having a hard time understanding how i'm supposed to call the addMessage function from the load function.
any help will be appreciated!