Answer to Question #331840 in C++ for Faye

Question #331840

1. Write a program using string function that will accept the name of the capital as input value and it will display the corresponding country.

CAPITAL                          COUNTRY

                  Ottawa                                  Canada

                  Washington D.C.                 United States

                  Moscow                                Russia

                  Rome                                     Italy


1
Expert's answer
2022-04-21T12:30:24-0400


//You can add another capital and country to programm
#include <iostream>
#include <string>
using namespace std;
int main() {
  string str;
  cout<<"Please enter capital:";
  cin>>str;
  if(str.compare("Ottawa")==0)
  {
    cout<<"Canada";
  }
  else if(str.compare("Minsk")==0)
    cout<<"Belarus";
  else if(str.compare("Washington D.C.")==0)
    cout<<"United States";
  else if(str.compare("Italy")==0)
    cout<<"Rome";
  else if(str.compare("Beijing")==0)
    cout<<"China";
  else if(str.compare("Quito")==0)
    cout<<"Ecuador";
  else if(str.compare("Tbilisi")==0)
    cout<<"Georgia";
  else if(str.compare("Berlin")==0)
    cout<<"German";
  else if(str.compare("Athens")==0)
    cout<<"Greece";
  else if(str.compare("Budapest")==0)
    cout<<"Hungary";
  else if(str.compare("Jakarta")==0)
    cout<<"Indonesia";
  else if(str.compare("Tokyo")==0)
    cout<<"Japan";
  else if(str.compare("Wellington")==0)
    cout<<"New Zealand";
  else if(str.compare("Islamabad")==0)
    cout<<"Pakistan";
  else
    cout<<"Sorry our base hasn't this capitale\nYou can search with Google";
  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 the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS