aprsc7

Array 2D

Nov 17th, 2019 (edited)
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     char input, town [6][13] = { "Alor Setar", "Ipoh", "Kangar", "Kuala Lumpur", "Mersing", "Melaka" };
  7.  
  8.     int i, first, second, distance [6][6] =
  9.     {
  10.         0,     258,    43,     475,    876,    623,
  11.         258,   0,      301,    217,    616,    365,
  12.         43,    301,    0,      518,    918,    667,
  13.         475,   217,    518,    0,      401,    148,
  14.         876,   616,    918,    401,    0,      246,
  15.         623,   365,    667,    148,    246,    0,
  16.     };
  17.  
  18.     cout << "Town Reference:\n";
  19.     for(i=0; i<6; i++)
  20.         cout << "\t" << i << " - " << town[i] << "\n";
  21.  
  22.     cout << "First town: ";
  23.     cin >> first;
  24.     cout << "Second town: ";
  25.     cin >> second;
  26.  
  27.     cout << "Distance between " << town[first] << " and " << town[second] << " is " << distance[first][second] << " km";
  28.  
  29.     cout << "\n\nRepeat (Y or N): ";
  30.     cin >> input;
  31.     if(input == 'y'||input == 'Y')
  32.         main();
  33. }
Add Comment
Please, Sign In to add comment