-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path2dm.cpp
65 lines (54 loc) · 1.41 KB
/
2dm.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdlib.h>
#include<iostream>
using namespace std;
int main(){
cout<<"Hello.\n";
char cont='y';
cout<<"Would you like to receive directions?(Type 'y' for yes and 'n' for no.)\n";
cin>>cont;
while(cont=='y'){
double currentX;
cout<<"What is your current x coordinate?\n";
cin>> currentX;
double currentY;
cout<<"What is your current y coordinate?\n";
cin>> currentY;
double destinationX;
cout<<"What is your destination's x coordinate?\n";
cin>> destinationX;
double destinationY;
cout<<"What is your destination's y coordinate?\n";
cin>> destinationY;
double horizDist;
horizDist=(destinationX-currentX);
double vertDist;
vertDist=(destinationY-currentY);
if(horizDist==0 && vertDist==0){
cout<<"You are already there.\n";
}
if(horizDist<0){
cout<<"Move " <<abs(horizDist)<< " spaces left.\n";
}
if(horizDist>0){
cout<<"Move " <<horizDist<< " spaces right.\n";
}
if(horizDist==0){
cout<<"Don't move horizontally.\n";
}
if(vertDist==0){
cout<<"Don't move vertically.\n";
}
if(vertDist>0){
cout<<"Move " <<vertDist<< " spaces up.\n";
}
if(vertDist<0){
cout<<"Move " <<abs(horizDist)<< " spaces down.\n";
}
cout<<"Would you like to receive directions again?(Type 'y' for yes and 'n' for no.)\n";
cin>>cont;
if(cont=='n'){
break;
}
}
cout<<"Bye.\n";
}