Test the knowledge of a user by giving him/her 7 choices of Capital Cities for each of the southern states of Mississippi, Arkansas, Missouri, Tennessee, Georgia, Alabama and Louisiana. Measure the score of user knowledge as each correct answer, score 100. Write the C++ code for the problem
Please find the code below:
#include<iostream>
// including the header
files
using namespace std;
int main()
// main()
{
int score=0;
// declaring a score variable
and initializing it to 0
int capital;
// declaring capital variable
to take capital from user
cout<<endl<<"*** Lets have a test on your
knowledge for southern state capitals ***";
cout<<endl<<"What is the capital of state
Mississippi?";
// Asking user for the
capital of state Mississippi
cout<<endl<<"1. Hattiesburg";
// providing the
options
cout<<endl<<"2. Jackson";
cout<<endl<<"3. Tupelo";
cout<<endl<<"4. Biloxi";
cout<<endl<<"5. Gulfport";
cout<<endl<<"6. Oxford";
cout<<endl<<"7. Meridian";
cout<<endl<<"Your choice:";
cin>>capital;
// taking user's choice in
capital variable
while(capital<1 || capital>7)
// if the user input is less
than 1 or more than 7
{
cout<<endl<<"Please
provide a valid choice [between 1 and 7]";
// showing approriate
message
cout<<endl<<"Your
choice:";
// again
asking for user's choice
cin>>capital;
}
if(capital==2)
// if the user's choice is
correct
{
cout<<endl<<"correct
answer!!!";
// printing correct answer
score=score+100;
// increasing score by 100
}
else
{
cout<<endl<<"Incorrect
answer.";
// else printing "incorrect answer"
}
cout<<endl<<endl<<"What is the
capital of state Arkansas?";
// Asking
user for the capital of Arkansan
cout<<endl<<"1. Fayetteville";
// providing the
options
cout<<endl<<"2. Fort Smith";
cout<<endl<<"3. Little Rock";
cout<<endl<<"4. Hot Springs";
cout<<endl<<"5. Jonesboro";
cout<<endl<<"6. Bentonville";
cout<<endl<<"7. Conway";
cout<<endl<<"Your choice:";
cin>>capital;
// taking choice in capital
variable
while(capital<1 || capital>7)
// if user's input is less
than 1 or more than 7
{
cout<<endl<<"Please
provide a valid choice [between 1 and 7]";
// print appropriate
message
cout<<endl<<"Your
choice:";
// ask
user for his/her choice again
cin>>capital;
}
if(capital==3)
// if correct answer
{
cout<<endl<<"correct
answer!!!";
// print appropriate message
score=score+100;
// increase score by 100
}
else
{
cout<<endl<<"Incorrect
answer.";
// else print "Incorrect answer"
}
cout<<endl<<endl<<"What is the
capital of state Missouri?";
// work so
on
cout<<endl<<"1. St. Louis";
cout<<endl<<"2. Kansas City";
cout<<endl<<"3. Springfield";
cout<<endl<<"4. columbia";
cout<<endl<<"5. Jefferson City";
cout<<endl<<"6. Saint Charles";
cout<<endl<<"7. Branson";
cout<<endl<<"Your choice:";
cin>>capital;
while(capital<1 || capital>7)
{
cout<<endl<<"Please
provide a valid choice [between 1 and 7]";
cout<<endl<<"Your
choice:";
cin>>capital;
}
if(capital==5)
{
cout<<endl<<"correct
answer!!!";
score=score+100;
}
else
{
cout<<endl<<"Incorrect
answer.";
}
cout<<endl<<endl<<"What is the
capital of state Tennessee?";
cout<<endl<<"1. Nashville";
cout<<endl<<"2. Memphis";
cout<<endl<<"3. Knoxville";
cout<<endl<<"4. Chattanooga";
cout<<endl<<"5. Galinburg";
cout<<endl<<"6. Franklin";
cout<<endl<<"7.ClarksVille";
cout<<endl<<"Your choice:";
cin>>capital;
while(capital<1 || capital>7)
{
cout<<endl<<"Please
provide a valid choice [between 1 and 7]";
cout<<endl<<"Your
choice:";
cin>>capital;
}
if(capital==1)
{
cout<<endl<<"correct
answer!!!";
score=score+100;
}
else
{
cout<<endl<<"Incorrect
answer.";
}
cout<<endl<<endl<<"What is the
capital of state Georgia?";
cout<<endl<<"1. Savannah";
cout<<endl<<"2. Augusta";
cout<<endl<<"3. Athens";
cout<<endl<<"4. Atlanta";
cout<<endl<<"5. Macon";
cout<<endl<<"6. Marietta";
cout<<endl<<"7. Alpharetta";
cout<<endl<<"Your choice:";
cin>>capital;
while(capital<1 || capital>7)
{
cout<<endl<<"Please
provide a valid choice [between 1 and 7]";
cout<<endl<<"Your
choice:";
cin>>capital;
}
if(capital==4)
{
cout<<endl<<"correct
answer!!!";
score=score+100;
}
else
{
cout<<endl<<"Incorrect
answer.";
}
cout<<endl<<endl<<"What is the
capital of state Alabama?";
cout<<endl<<"1. Birmingham";
cout<<endl<<"2. Mobile";
cout<<endl<<"3. Huntsville";
cout<<endl<<"4. Auburn";
cout<<endl<<"5. Tuscaloosa";
cout<<endl<<"6. Dothan";
cout<<endl<<"7. Montgomery";
cout<<endl<<"Your choice:";
cin>>capital;
while(capital<1 || capital>7)
{
cout<<endl<<"Please
provide a valid choice [between 1 and 7]";
cout<<endl<<"Your
choice:";
cin>>capital;
}
if(capital==7)
{
cout<<endl<<"correct
answer!!!";
score=score+100;
}
else
{
cout<<endl<<"Incorrect
answer.";
}
cout<<endl<<endl<<"What is the
capital of state Louisiana?";
cout<<endl<<"1. New Orleans";
cout<<endl<<"2. Lafayette";
cout<<endl<<"3. Shreveport";
cout<<endl<<"4. Lake Charles";
cout<<endl<<"5. Metairie";
cout<<endl<<"6. Baton Rouge";
cout<<endl<<"7. Alexandria";
cout<<endl<<"Your choice:";
cin>>capital;
while(capital<1 || capital>7)
{
cout<<endl<<"Please
provide a valid choice [between 1 and 7]";
cout<<endl<<"Your
choice:";
cin>>capital;
}
if(capital==6)
{
cout<<endl<<"correct
answer!!!";
score=score+100;
}
else
{
cout<<endl<<"Incorrect
answer.";
}
cout<<endl<<endl<<"Your final score
is:"<<score;
// print the score of the
user
}
=============================================================================================
Output:


===========================================================================================
Test the knowledge of a user by giving him/her 7 choices of Capital Cities for each...