I'm stuck on trying to add quantities to this list when it returns the output. It is essentially a list entered by the user that starts with a quantity and is followed by a word. It is then supposed to output the same list but in alphabetical order. I currently have it alphabetized but the numbers that the user enters on the same line, are returned on a separate line from the word when returned in alphabetical order. I know I am prompted to use parallel arrays but have no clue how to incorporate them into this. Nobody has been able to reply to me but I know it is do-able. Thank you all in advance!!
#include <iostream>
#include <string>
#include <iomanip>
#include "functions.h"
#include <algorithm>
#include <set>
using namespace std;
void print(const string& item)
{
cout << item << endl;
}
int main(void)
{
const int MAX_LENGTH = 256;
string items [MAX_LENGTH];
int quantities [ MAX_LENGTH];
string itemChoice;
string qtyChoice;
int numItems= 0;
int randomArray[MAX_SIZE];
{
set<string> sortedItems;
cout << " (type \"exit\" twice to exit, now press enter twice to begin listing your shopping list.): ";
getline (cin, qtyChoice);
getline(cin, itemChoice);
for (int i = 1; ; i++)
{
string itemChoice;
string wholeOrder;
cout << i << ". ";
cin >> itemChoice;
cin >> qtyChoice; // this is how I got it to intake #'s
//getline (cin, qtyChoice);// putting these here actually allow both items to be on one line!! but it leaves awkward spaces.
//getline(cin, itemChoice);
//getline (cin, qtyChoice);
if (itemChoice == "exit")
{
break;
}
sortedItems.insert(qtyChoice);
sortedItems.insert (itemChoice);
//sortedItems.insert(itemChoice);
}
for_each(sortedItems.begin(), sortedItems.end(), &print);
return 0;
}
this is my code and this is what happens as output
(type "exit"to exit, now press enter twice to begin listing your list.):
1. 3828 eijsd
2. 38238 shd
3. 382 hsdid
4. exit
382
38238
3828
eijsd
hsdid
shd