Question: Can you please convert the program into a guessing game. The guessing game will randomly select a region, a state, a region's capital, or a
Can you please convert the program into a guessing game. The guessing game will randomly select a region, a state, a region's capital, or a state's capital. The guessing game will then display the selected entity's name and invite the player to guess the entity's other half.
If the guessing game displays a state's or region's name then the guessing game will ask the user for the state's or region's capital and if the guessing game displays a state's or region's capital then the guessing game will ask the user for the state's or region's name. The guessing game will then tell the user if the user's guess is right or wrong.
If the guessing displays "Kentucky" then the guessing game asks the user to enter "Kentucky"'s capital's name. The guessing game reads the user's guess and tells the user if the user's guess is right or wrong.
if the guessing game displays "Pago Pago" then the guessing game asks the user to enter "Pago Pago"'s region's name. The guessing game reads the user's guess and tells the user if the user's guess is right or wrong.
The program from bottom needs to be used to convert into game the .txt file . Thank You,
.cpp file
#include
#include
#include
#include
#include
#include
using namespace std;
struct Couple
{
Couple(const string& new_first, const string& new_second)
{
first = new_first;
second = new_second;
}
string first;
string second;
};
string trim(const string& source);
string toupper(const string& source);
int find(vector
int main()
{
const string inputfilename = "States&Territories&Capitals.txt";
const string message1 = " does not open";
ifstream finp(inputfilename);
if (finp.good())
{
vector
vector
string capital, region;
while (getline(finp, region, ' '))
{
getline(finp, capital, ' ');
capital = trim(capital);
region = trim(region);
capital = toupper(capital);
region = toupper(region);
rpairs.push_back(Couple(region, capital));
cpairs.push_back(Couple(capital, region));
}
finp.close();
const string prompt = "Enter the name of a territory, a state, or a capital: ";
const string message2 = "The capital of ";
const string message3 = " is ";
const string message4 = " is not a capital, a state, or a territory";
unsigned seed = (unsigned)time(nullptr);
cout << prompt;
stringname;
while (getline(cin, name, ' '), name = trim(name), name.length() > 0)
{
name = toupper(name);
int rwhere = find(rpairs, name);
int cwhere = find(cpairs, name);
if (rwhere != -1)
cout << message2 << name << message3 << rpairs[rwhere].second << endl;
else if(cwhere != -1)
cout << message2 < else cout << name << message4 << endl; cout << prompt; } } else cout << inputfilename << message1 << endl; system("pause"); return 0; } int find(vector { int i = 0; while (i < couples.size() && couples[i].first != key) i++; return i < couples.size() ? i : -1; } string trim(const string& source) { if (source.empty()) return source; int begin = 0; int end = source.length() - 1; while (begin < end && isspace(source[begin])) begin++; while (begin < end && isspace(source[end])) end--; return source.substr(begin, end - begin + 1); } string toupper(const string& source) { if (source.empty()) return source; string edited = ""; for (int i = 0; i < source.length(); ++i) edited = edited + (char)toupper(source[i]); return edited; } States&Territories&Capitals.txt Alabama Montgomery Alaska Juneau Arizona Phoenix Arkansas Little Rock California Sacramento Colorado Denver Connecticut Hartford Delaware Dover Florida Tallahassee Georgia Atlanta Hawaii Honolulu Idaho Boise Illinois Springfield Indiana Indianapolis Iowa Des Moines Kansas Topeka Kentucky Frankfort Louisiana Baton Rouge Maine Augusta Maryland Annapolis Massachusetts Boston Michigan Lansing Minnesota Saint Paul Mississippi Jackson Missouri Jefferson City Montana Helena Nebraska Lincoln Nevada Carson City New Hampshire Concord New Jersey Trenton New Mexico Santa Fe New York Albany North Carolina Raleigh North Dakota Bismarck Ohio Columbus Oklahoma Oklahoma City Oregon Salem Pennsylvania Harrisburg Rhode Island Providence South Carolina Columbia South Dakota Pierre Tennessee Nashville Texas Austin Utah Salt Lake City Vermont Montpelier Virginia Richmond Washington Olympia West Virginia Charleston Wisconsin Madison Wyoming Cheyenne American Samoa Pago Pago Guam Hagatna Northern Mariana Islands Saipan Puerto Rico San Juan U.S. Virgin Islands Charlotte Amalie
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
