Locating avenues’ addresses in mid-Manhattan is not easy; for example, the nearest cross street
to 866 3rd Avenue is 53rd Street, whereas the nearest cross street to 866 Second Avenue is 46st
Street. To locate approximately the nearest numbered cross street for a given avenue address, the
following procedure can be used:
Cancel the last digit of the address (First digit from the right), divide by 2, and add or subtract
the number given in the following table:
I cant understand this question so I Would really need your help... thank you in advance..
ok I did it and here is the code for anyone who wants to see it
#include <iostream>
#include <cmath>
#include <string>
usingnamespace std ;
int main ()
{
string response ;
int x=0,y=0,z,address,number ;
cout << "This program computes the nearest cross street in mid-Manhattan from the Avenue address. \n " ;
cout << "Would you like to try it? (Y/N) \n " ;
cin >> response ;
while (response != "y" && response != "Y" && response != "n" && response != "N" ) // locks use up in loop if he keeps entering wrong response
{
cout << "Error not valid entry try again \n " ;
cout << "Would you like to try it? (Y/N) \n " ;
cin >> response ;
}
while (response == "Y" || response == "y" ) // if the response is still Y it will keep going until user enters N or n
{
cout << "Please enter the avenue address " ;
cin >> address ;
while (address <100 || address>=1000)
{
cout << "please enter an address between 100 and 1000 \n " ; // keeps user in a loop until he enters a correct address number
cin >> address ;
}
cout << "Please enter the avenue number ";
cin >> number ;
switch (number)
{
case 1 :
x=address ; // assign x to address and y to avenue number to use in calculations while keeping the vaule of address and avenue number saved
y=number ;
x=x/10 ;
x=x/2 ;
z=x+3 ;
cout << "The nearest cross street to " <<address << " " << number << "is " << z << " street" <<endl ; // output of the street number
cout << "would you like to try again? (y)(n)? \n " ;
cin >> response ;
break ;
case 2 :
x=address ;
y=number ;
x=x/10 ;
x=x/2 ;
z=x+3 ;
cout << "The nearest cross street to " <<address << " " << number << "is " << z << " street" <<endl ;
cout << "Would you like to try it? (Y/N) \n " ;
cin >> response ;
break ;
case 3 :
x=address ;
y=number ;
x=x/10 ;
x=x/2 ;
z=x+10 ;
cout << "The nearest cross street to " <<address << " " << number << "is " << z << " street" <<endl ;
cout << "Would you like to try it? (Y/N) \n " ;
cin >> response ;
break ;
case 4 :
x=address ;
y=number ;
x=x/10 ;
x=x/2 ;
z=x+8 ;
cout << "The nearest cross street to " <<address << " " << number << "is " << z << " street" <<endl ;
cout << "Would you like to try it? (Y/N) \n " ;
cin >> response ;
break ;
case 5 :
if (address>=100 && address <=200)
{
x=address ;
y=number ;
x=x/10 ;
x=x/2 ;
z=x+13 ;
cout << "The nearest cross street to " <<address << " " << number << "is " << z << " street" <<endl ;
cout << "Would you like to try it? (Y/N) \n " ;
cin >> response ;
break ;
}
elseif (address>=201 && address <=400)
{
x=address ;
y=number ;
x=x/10 ;
x=x/2 ;
z=x+16 ;
cout << "The nearest cross street to " <<address << " " << number << "is " << z << " street" <<endl ;
cout << "Would you like to try it? (Y/N) \n " ;
cin >> response ;
break ;
}
else
cout << "please enter an address between 100 and 400,would you try again? (y)(n) \n " ;
cin>> response ;
break ;
case 6 :
x=address ;
y=number ;
x=x/10 ;
x=x/2 ;
z=x-12 ;
cout << "The nearest cross street to " <<address << " " << number << "is " << z << " street" <<endl ;
cout << "Would you like to try it? (Y/N) \n " ;
cin >> response ;
break ;
case 7 :
x=address ;
y=number ;
x=x/10 ;
x=x/2 ;
z=x+12 ;
cout << "The nearest cross street to " <<address << " " << number << "is " << z << " street" <<endl ;
cout << "Would you like to try it? (Y/N) \n " ;
cin >> response ;
break ;
case 8 :
x=address ;
y=number ;
x=x/10 ;
x=x/2 ;
z=x+10 ;
cout << "The nearest cross street to " <<address << " " << number << "is " << z << " street" <<endl ;
cout << "Would you like to try it? (Y/N) \n " ;
cin >> response ;
break ;
case 10 :
x=address ;
y=number ;
x=x/10 ;
x=x/2 ;
z=x+14 ;
cout << "The nearest cross street to " <<address << " " << number << "is " << z << " street" <<endl ;
cout << "Would you like to try it? (Y/N) \n " ;
cin >> response ;
break ;
default :
cout << "Error avenue number, Would you like to try again? (y)(n) \n " ; // if use enters an avenue number more than 10
cin >> response ; // or less than 0 user will have choice of trying again
break ;
}
}
if (response == "N" || response == "n") // if user enters N or n then program will end
cout << "Thank you for using.. we hope we fulfilled your needs" << endl ;
return 0 ;
}