In: Computer Science
Can someone please tell me why I am getting errors. I declared the map and it's values like instructed but it's telling me I'm wrong.
#include <iostream>
#include <stdio.h>
#include <time.h>
#include <chrono>
#include <string>
#include <cctype>
#include <set>
#include <map>
#include "d_state.h"
using namespace std;
int main()
{
string name;
map<string,string> s;
map<string,string>::iterator it;
s[“Maryland”] = "Salisbury";
s[“Arizona”] = "Phoenix";
s[“Florida”] = "Orlando";
s[“Califonia”] = "Sacramento";
s[“Virginia”] = "Richmond";
cout << "Enter a state:" << endl;
cin >> name;
if( !name.empty() )
{
name[0] = toupper( name[0] );
for( int i = 1 ; i < name.length() ; i++
)
name[i] = tolower(
name[i] );
}
/*it = s.find(name);
if (it != s.end())
{
cout << name << ", " <<
s[name] << endl;
}
else
{
cout << name << " is not in the set"
<< endl;
}*/
return 0;
}
->You are getting an error because you are using curly quotation marks (“......”) instead of ASCII quotation marks ( "....." ).
-> You should write "Maryland" instead of “Maryland”.
Refer to the below code after correction:
#include <iostream>
#include <stdio.h>
#include <time.h>
#include <chrono>
#include <string>
#include <cctype>
#include <set>
#include <map>
//#include "d_state.h"
using namespace std;
int main()
{
string name;
map<string,string> s;
map<string,string>::iterator it;
s["Maryland"] = "Salisbury";
s["Arizona"] = "Phoenix";
s["Florida"] = "Orlando";
s["Califonia"] = "Sacramento";
s["Virginia"] = "Richmond";
cout << "Enter a state: " ;
cin >> name;
if( !name.empty() )
{
name[0] = toupper( name[0] );
for( int i = 1 ; i < name.length() ; i++ )
name[i] = tolower( name[i] );
}
it = s.find(name);
if (it != s.end())
{
cout << name << ", " << s[name] << endl;
}
else
{
cout << name << " is not in the set" << endl;
}
return 0;
}
Test run: