Advertisement
Guest User

Untitled

a guest
Nov 16th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <fstream>
  4.  
  5.  
  6. void intro();
  7. int country_Array();
  8. int i = 0;
  9. std::string cName[100];
  10. std::string cCapital[100];
  11. int totalNumOfCountries;
  12.  
  13. int main()
  14. {
  15.     intro();
  16.     country_Array();
  17.    
  18.  
  19.     return 0;
  20. }
  21. void intro()
  22. {
  23. std::cout<< std::setw(5) << "Welcome to the Country Selector, please choose from one of the following countries and you will see all the states and capitals: " << std::endl;
  24. }
  25.  
  26. int country_Array()
  27. {
  28.     int countryChosen;
  29.     std::string countryName;
  30.    
  31.     std::cout << std::setw(10) << "1. European, 2. Middle-Eastern, or 3.Asian country" << std::endl;
  32.     std::cout << std::setw(10) << "Select the number you wish to see: ";
  33.     std::cin >> countryChosen;
  34.    
  35.     switch (countryChosen)
  36.     {
  37.         case 1: countryName = "europeanData.txt";
  38.             break;
  39.         case 2: countryName = "middleEast.txt";
  40.             break;
  41.         case 3: countryName = "Asian.txt";
  42.             break;
  43.  
  44.     }
  45.     std::ifstream inFile;
  46.     inFile.open(countryName);
  47.    
  48.     if(inFile.fail())
  49.     {
  50.         std::cout << "The country.txt file failed to open";
  51.         exit(-1);
  52.     }
  53.     while (inFile)
  54.     {
  55.         inFile >> cName[i];
  56.         inFile >> cCapital[i];
  57.         i++;
  58.     }
  59.     return i-2;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement