#include <iostream>
#include <cctype>
#include <string>
#include <vector>
usingnamespace std;
char choice();
int main() {
string bus;
vector<string>name;
while (choice()=='Y') {
cout << "Please enter name of your business." << endl;
cin >> bus ;
name.push_back(bus);
if (name.size() > 1) {
cout << "The name of your buisnesses are: " << endl;
}
else {
cout << "The name of your business is: ";
}
for (unsignedint i = 0; i < name.size(); i++) {
cout << '\n'<<name[i] << endl;
}
}
system("pause");
return 0;
}
char choice() {
cout << "\nWould you like to use the program?" << endl;
char x;
cin >> x;
cin.ignore(INT_MAX, '\n');
return toupper(x);
}
OP: you can even use set (unique strings only) or multi-set (non-unique strings as well) that will sort the strings automatically or by any user-defined criterion:
OP: one thing to bear in mind is that if you have any upper case strings in the vector then without using any other libraries (like algorithm, locale etc) I'm not sure you can get the words beginning with upper and lower case versions of the same letter next to each other with the program as it stands now:
for e.g:
1 2
vector<string> name {"harry", "tom", "apple", "Tank", "zoology", "basket"};
Output:Tank**apple**basket**harry**tom**zoology**