Dec 21, 2009 at 1:16pm UTC
Hi everyone.
Im having problems getting the program to compare strings in the array.
The game is supposed to ask the user what is the capital of a random country (which it does), and the user will input the name, then the game will tell if correct or incorrect, if incorrect display the correct name. But I cant get it to compare the strings in the array. Thanks for the help.
This is the code.
#include <iostream>
#include <String.h>
#include <Stdlib.h>
#include <Stdio.h>
#include <Time.h>
using namespace std;
char Country [63] [255] = {"Albania",
"Andorra",
"Armenia",
"Austria",
"Azerbaijan",
"Belarus",
"Belgium",
"Bosnia Hezergovina",
"Bulgaria",
"Croatia",
"Cyprus",
"Czech Republic",
"Denmark",
"Estonia",
"Finland",
"France",
"Georgia",
"Germany",
"Greece",
"Hungary",
"Iceland",
"Ireland",
"Italy",
"Kazakhstan",
"Latvia",
"Liechstein",
"Lithuania",
"Luxembourg",
"Macedonia",
"Malta",
"Moldova",
"Monaco",
"Montenegro",
"Netherldands",
"Norway",
"Poland",
"Portugal",
"Romania",
"Russia",
"San Marino",
"Serbia",
"Slovakia",
"Slovenia",
"Spain",
"Sweden",
"Switzerland",
"Turkey",
"Ukraine",
"United Kingdom",
"Vatican City",
"Aland",
"Akrotiri & Dhekelia",
"Faroe Islands",
"Gibraltar",
"Guernsey",
"Isle of man",
"Jersey",
"Abkhazia",
"Kosovo",
"Northern Cyprus",
"South Ossetia",
"Nagorno Karabakh",
"Transnistria"};
char Capital [63] [255] = {"Tirana",
"Andorra la Vella",
"Yerevan",
"Vienna",
"Baku",
"Minsk",
"Brussels",
"Sarajevo",
"Sofia",
"Zagreb",
"Nicosia",
"Prague",
"Copenhagen",
"Tallinn",
"Helsinki",
"Paris"
"Tbilisi",
"Berlin",
"Athens",
"Budapest",
"Reykjavik",
"Dublin",
"Rome",
"Astana",
"Riga",
"Vaduz",
"Vilnius",
"Luxembourg City",
"Skopje",
"Valletta",
"Chisinau",
"Monaco",
"Podgorica",
"Amsterdam",
"Oslo",
"Warsaw",
"Lisbon",
"Bucharest",
"Moscow",
"City of San Marino",
"Belgrade",
"Bratislava",
"Ljubljana",
"Madrid",
"Stockholm",
"Bern",
"Ankara",
"Kiev",
"London",
"Vatican City",
"Mariehamn",
"Episkopi Cantonment",
"Torshvan",
"Gibraltar",
"St.Peter Port",
"Douglas",
"St.Helier",
"Sukhumi",
"Pristina",
"Lefkosa",
"Tskhinvali",
"Stepanakert",
"Tiraspol"};
int main()
{
srand(time(0));
int correct=0;
int incorrect=0;
bool endgame=false,answr;
while(endgame==false)
{
int RandNum = rand() % 63;
if(!strlen(Country[RandNum]))
{
while(!strlen(Country[RandNum]))
{
RandNum = rand() % 63;
}
}
char Answer[255];
cout<< "Guess the capital of " << Country[RandNum]<<endl;
cin >> Answer;
if (Answer==Capital[RandNum])answr=true;
else answr=false;
if(answr==true) {correct ++; cout << "\nYou guessed right\n";}
if(answr==false) {incorrect++; cout << "\nYou guessed wrong. The correct answer is "<<Capital[RandNum]<<endl;}
if (correct == 3)
{
cout << "Wow! You guessed all 50 country capitals correct\n";
endgame=true;
}
if (incorrect == 5)
{
incorrect ++;
cout << " You had 5 chances and missed\n"
<< " you need to learn more geography\n"
<< " the correct answer is "<< Answer;
endgame=true;
}
}
}