Dev - C++ - Dimensiones de un área

 
Vista:

Dimensiones de un área

Publicado por Alejandro montiel Suriano (1 intervención) el 18/05/2017 11:28:51
Pero el programa no logro hacerlo compila.

//Realice un programa que lea las dimensiones de un área sobre las que se moverá un robot, las coordenadas x,y de la posición del robot, y las coordenadas x,y de la posición de la meta del robot. Deberá leer tambien si el robot mira hacia el norte, sur, este u oeste. El programa deberá indicar hacia donde tiene que girar el robot (derecha o izquierda), cuántos grados (90 o 180) y cuántos pasos tiene que dar hasta llegar a su meta. Después preguntará si desea que el robot camine hacia una nueva meta, y si ése es el caso, leerá nuevamente otras coordenadas x,y.


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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "stdio.h"
int ancho=0,largo,robotx=0,roboty=0,comidax=0,comiday=0,show=0,error=0,confirmadox=0;
int confirmadoy=0,giro=0,direc=0,x=0,y=0, prefx=0, prefy=0,mostrar=1,cerrar;
char direccion[1]; char continuar[2];
int main(){
    while(cerrar==0){
   if(mostrar==1){
printf("Ancho del cuarto (X): ");
scanf("%d",&ancho);
printf("Largo del cuarto (Y): ");
scanf("%d",&largo);
do{
printf("X del robot: ");
scanf("%d",&robotx);}
while (robotx>ancho||robotx<0);
do{
printf("Y del robot: ");
scanf("%d",&roboty);}
while (roboty>largo||roboty<0);
    }
if (mostrar==0){
printf("\n------------------------------------\nsi=si\tno=no\nDesea seguir comiendo?:");
scanf("%s",continuar);
if(strcmp(continuar,"si")==0){
prefx=0;prefy=0;robotx=comidax; roboty=comiday;confirmadox=0;confirmadoy=0; cerrar=0;
}
else{cerrar=1;}
}
if(cerrar==0){
mostrar=0;
do{
printf("X de la comida: ");
scanf("%d",&comidax);}
while (comidax>ancho||comidax<0);
do{
printf("Y de la comida: ");
scanf("%d",&comiday);}
while (comiday>largo||comiday<0);
do{
printf("\nn=norte\ts=sur\te=este\to=oeste\nHacia a donde observa el robot: ");
scanf("%s",direccion);
getchar();
if(strcmp(direccion,"n")==0){error=1;direc=1;}
else{
if(strcmp(direccion,"s")==0){error=1;direc=-1;}
else{
if(strcmp(direccion,"e")==0){error=1;direc=2;}
else{
if(strcmp(direccion,"o")==0){error=1;direc=-2;}
else{
error=0;
}
}
}}
}while(error==0);
if(comidax>robotx)
{
x=2;
}
if(comidax<robotx)
{
x=-2;
}
if(comiday>roboty)
{
y=1;
}
if(comiday<roboty)
{
y=-1;
}
if(comidax==robotx&&comiday==roboty){
    printf("\nComer\n");
}
if(x==direc){
prefx=1;
}
if((direc+x)==0){giro=1;printf("\nGire 180 grados\n");prefx=1;}
if(y==direc){
prefy=1;
}
if((direc+y)==0){giro=1;printf("\nGire 180 grados\n");prefy=1;}
if(prefx==1){
confirmadox=1;
if(comidax>robotx)
{
    if (confirmadoy==1){printf("\nGira 90 grados hacia el este\n");}
printf("\n%d pasos hacia el este\n",comidax-robotx);
}
if(comidax<robotx)
{
    if (confirmadoy==1){printf("\nGira 90 grados hacia el oeste\n");}
printf("\n%d pasos hacia el oeste\n",robotx-comidax);
}
if(comiday>roboty)
{
    if (confirmadox==1){printf("\nGira 90 grados hacia el norte\n");}
printf("\n%d pasos hacia el norte\n",comiday-roboty);
}
if(comiday<roboty)
{
if (confirmadox==1){printf("\nGira 90 grados hacia el sur\n");}
printf("\n%d pasos hacia el sur\n",roboty-comiday);
}
}
else{
if(prefy==1){
confirmadoy=1;
if(comiday>roboty)
{
    if (confirmadox==1){printf("\nGirar 90 grados hacia el norte\n");}
printf("\n%d pasos hacia el norte\n",comiday-roboty);
}
if(comiday<roboty)
{
if (confirmadox==1){printf("\nGirar 90 grados hacia el sur\n");}
printf("\n%d pasos hacia el sur\n",roboty-comiday);
}
if(comidax>robotx)
{
    if (confirmadoy==1){printf("\nGirar 90 grados hacia el este\n");}
printf("\n%d pasos hacia el este\n",comidax-robotx);
}
if(comidax<robotx)
{
    if (confirmadoy==1){printf("\nGirar 90 hacia el este\n");}
printf("\n%d pasos hacia el oeste\n",robotx-comidax);
}
}
}
}
}
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder