Question

In: Computer Science

Can someone please tell me why I am getting errors. I declared the map and it's...

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;
}

Solutions

Expert Solution

->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:


Related Solutions

Okay, can someone please tell me what I am doing wrong?? I will show the code...
Okay, can someone please tell me what I am doing wrong?? I will show the code I submitted for the assignment. However, according to my instructor I did it incorrectly but I am not understanding why. I will show the instructor's comment after providing my original code for the assignment. Thank you in advance. * * * * * HourlyTest Class * * * * * import java.util.Scanner; public class HourlyTest {    public static void main(String[] args)     {        ...
can someone tell me if i am wrong on any of these???? THANKS In order to...
can someone tell me if i am wrong on any of these???? THANKS In order to be able to deliver an effective persuasive speech, you need to be able to detect fallacies in your own as well as others’ speeches. The following statements of reasoning are all examples of the following fallacies: Hasty generalization, mistaken cause, invalid analogy, red herring, Ad hominem, false dilemma, bandwagon or slippery slope. 1. __________bandwagon fallacy_______ I don’t see any reason to wear a helmet...
I am getting 7 errors can someone fix and explain what I did wrong. My code...
I am getting 7 errors can someone fix and explain what I did wrong. My code is at the bottom. Welcome to the DeVry Bank Automated Teller Machine Check balance Make withdrawal Make deposit View account information View statement View bank information Exit          The result of choosing #1 will be the following:           Current balance is: $2439.45     The result of choosing #2 will be the following:           How much would you like to withdraw? $200.50      The...
Can someone please tell me on how can I have a double and character as one...
Can someone please tell me on how can I have a double and character as one of the items on my list? Thanks! This is what I got so far and the values I am getting are all integers. #pragma once #include <iostream> class Node { public:    int data;    Node* next;       // self-referential    Node()    {        data = 0;        next = nullptr;    }    Node(int value)    {        data...
Can anyone explain to me why I am getting an access violation when I try to...
Can anyone explain to me why I am getting an access violation when I try to add notes? It occurs when I try to set the "pLast" pointer to the previous node (for a doubly linked list). The code worked as singly linked list. When I added a "pLast" pointer and the needed code to make it a doubly linked list everything broke. #include <iostream> #include <stdlib.h> using namespace std; //build class that has a private function to inc count....
can someone tell me why I'm getting the error code on Eclipse IDE: Error: Main method...
can someone tell me why I'm getting the error code on Eclipse IDE: Error: Main method is not static in class StaticInitializationBlock, please define the main method as:    public static void main(String[] args) This is what I'm working on class A { static int i; static { System.out.println(1); i = 100; } } public class StaticInitializationBlock { static { System.out.println(2); } public static void main(String[] args) { System.out.println(3); System.out.println(A.i); } }
Please can someone explain this to me. I am stuck at the last two questions Use...
Please can someone explain this to me. I am stuck at the last two questions Use the following information to calculate your answers to questions 10 through 14. Test scores of 10 individuals before and after a training program are shown below. Note: despite the sample size, assume that the sampling distribution of T+ can still be approximated by a normal distribution. Individual Score After the Program Score Before the Program 1 57 59 2 62 57 3 60 60...
Hello Everyone, Can anyone tell me why my program will not run? I am trying to...
Hello Everyone, Can anyone tell me why my program will not run? I am trying to work on abstract base classes... not sure what is going on. import math from abc import ABC from abc import abstractmethod #TODO: convert this to an ABC class Shape(ABC): def __init__(self): self.name = "" def display(self): print("{} - {:.2f}".format(self.name, self.get_area())) #TODO: Add an abstractmethod here called get_area @abstractmethod def get_area(self): if self.name == "Circle": get_area()= 3.14 * radius * radius else: get_area() = self.length...
I have to complete a template for pathophysiology , can someone tell me the pathophysiology of...
I have to complete a template for pathophysiology , can someone tell me the pathophysiology of pain. This is for a pathophysiology class
please show me or tell me a trick, on how can i tell right away when...
please show me or tell me a trick, on how can i tell right away when a characteristics equation(system) is 1)overdamped 2)underdamped 3)critically damped 4) nonlinear show each an example write neatly!!!!!
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT