63 041
Assignments Done
99,1%
Successfully Done
In July 2018

Answer to Question #30260 in C++ for tindoh

Question #30260
Write a program that prompts the user to enter in an unlimited number of colors. Test to make sure that the user did not already enter a color before storing it (i.e. “We’re sorry, but you’ve already added the color ‘yellow’”). When the user types the string “exit” you should stop collecting colors. The print out the colors entered in alphabetical order.
Expert's answer
#include <set>
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

set<string> a;

int main()
{
string s;
cin>>s;
while(s!="exit")
{
if(a.find(s)==a.end()) a.insert(s); else
cout<<"We're sorry, but you've already added the color '"<<s<<"'"<<endl;
cin>>s;
}
for(set<string>::iterator it=a.begin(); it!=a.end(); it++)
cout<<*it<<' ';
cout<<endl;
system("pause");
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions