/* Guide to Manhattan Street Numbers (from back of Panchito's business card, 105 MacDougal Street) Cancel last figure of house number. Divide remainder by two and add the key number below. Result is approximately nearest street. 3 First Avenue 3 Second Avenue 10 Third Avenue 8 Fourth Avenue 13 1 to 200 Fifth Avenue 16 201 to 400 Fifth Avenue 18 401 to 600 Fifth Avenue 20 601 to 775 Fifth Avenue -18 776 to 1286 Fifth Avenue and don't divide by 2 -12 Sixth Avenue 12 1 to 1800 Seventh Avenue 20 above 1800 Seventh Avenue 9 Eighth Avenue 13 Ninth Avenue 13 Tenth Avenue 15 Eleventh Avenue 59 Amsterdam Avenue 59 Columbus Avenue 22 Lexington Avenue 27 Madison Avenue 35 Park Avenue 59 West End Avenue 60 Central Park West and don't divide by 2 73 1 to 567 Riverside Drive and don't divide by 2 78 above 567 Riverside Drive and don't divide by 2 1 to 754 Broadway -- below Eighth Street -29 754 to 858 Broadway -25 858 to 958 Broadway -31 above 1000 Broadway Example: 350 Park Avenue. Cancel last figure (0), divide by 2, and add key number (34). Answer: 51st Street. Street numbers commence as follows: East Side: 1 at 5th Avenue 101 at Park or 4th Avenue 201 at 3rd Avenue 301 at 2nd Avenue 401 at 1st Avenue 501 at York Avenue or Avenue A 601 at Avenue B West Side: 1 at 5th Avenue 101 at 6th Avenue 201 at 7th Avenue 301 at 8th Avenue 401 at 9th Avenue 501 at 10th Avenue 601 at 11th Avenue */ #include #include #include using namespace std; int main() { const int Amsterdam = 12; const int Columbus = 13; const int Lexington = 14; const int Madison = 15; const int Park = 16; const int WestEnd = 17; const int CentralParkWest = 18; const int RiversideDrive = 19; const int Broadway = 20; const string name[] = { "", //array subscripts always start at zero "First Avenue", "Second Avenue", "Third Avenue", "Fourth Avenue", "Fifth Avenue", "Sixth Avenue", "Seventh Avenue", "Eighth Avenue", "Ninth Avenue", "Tenth Avenue", "Eleventh Avenue", "Amsterdam Avenue", "Columbus Avenue", "Lexington Avenue", "Madison Avenue", "Park Avenue", "West End Avenue", "Central Park West", "Riverside Drive", "Broadway" }; const size_t n = sizeof name / sizeof name[0]; const int key[] = { 0, //array subscripts always start at zero 3, //First Avenue starts at Houston Street 3, //Second Avenue starts at Houston Street 10, //Third Avenue starts at Eighth Street 8, //Fourth Avenue starts at Eighth Street 0, //Fifth Avenue -12, //Sixth Avenue 0, //Seventh Avenue 9, //Eighth Avenue starts at 12th Street 13, //Ninth Avenue (becomes Columbus at 59th St.) 13, //Tenth Avenue (becomes Amsterdam at 59th St.) 15, //Eleventh Avenue starts at 14th Street 59, //Amsterdam Avenue starts at 59th Street 59, //Columbus Avenue starts at 59th Street 22, //Lexington Avenue starts at 21st Street 27, //Madison Avenue starts at 23rd Street 35, //Park Avenue starts at 32nd Street 59, //West End Avenue starts at 59th Street 60, //Central Park West starts at 59th Street 0, //Riverside Drive 0 //Broadway }; cout << "Avenue number (1 to 11 inclusive), " << "or one of the following:\n"; for (size_t i = Amsterdam; i <= Broadway; ++i) { //tab character cout << "\t" << i << " " << name[i] << "\n"; } cout << "\n"; cout << "Avenue: "; size_t avenue; //uninitialized variable cin >> avenue; if (avenue <= 0 || avenue >= n) { cerr << "Must be in range 1 to " << n - 1 << " inclusive.\n"; return EXIT_FAILURE; } cout << "Building number: "; int building; //uninitialized variable cin >> building; if (building <= 0) { cerr << "Can't be negative.\n"; return EXIT_FAILURE; } int divisor = 20; int k = key[avenue]; switch (avenue) { case 5: if (building <= 200) { k = 13; } else if (building <= 400) { k = 16; } else if (building <= 600) { k = 18; } else if (building <= 775) { k = 20; } else if (building <= 1286) { k = -18; divisor = 10; } break; case 7: if (building <= 1800) { k = 12; } else { k = 20; } break; case CentralParkWest: divisor = 10; break; case RiversideDrive: divisor = 10; if (building <= 567) { k = 73; } else { k = 78; } break; case Broadway: if (building <= 754) { divisor = 100; //below Eighth Street k = 0; } else if (building <= 858) { k = -29; } else if (building <= 958) { k = -25; } else { k = -31; } break; } const int street = building / divisor + k; cout << building << " " << name[avenue] << " is at " << street << " Street.\n"; return EXIT_SUCCESS; }