I am trying to make a program which will take in a list from the user with both quantities and words. However, I have everything done but am unable to combine the numbers with according word(s) on the same line. It continues to output all the numbers and then output all the words. Also the words should be outputted in alphabetical order. Thank you in advance!
{
set<string> sortedItems;
cout << " (type \"exit\" to exit, now press enter to begin listing): ";
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 take #'s
if (itemChoice == "exit")
{
break;
}
sortedItems.insert(qtyChoice);
sortedItems.insert (itemChoice);
for_each(sortedItems.begin(), sortedItems.end(), &print);
return 0;
}
Instead of outputting the number of each and name of each on the same line, it does this:
1. 23 hello
2. 18 thanks
3. 37 goodbye
4. exit
exit
18
23
37
goodbye
hello
thanks