Dev - C++ - Datos no se imprimen correctamente

 
Vista:

Datos no se imprimen correctamente

Publicado por Shumaro (2 intervenciones) el 16/10/2020 18:20:08
Debo imprimir una serie de datos de forma horizontal, no uso saltos de linea, pero se imprimen verticalmente, la funcion que hace esto se encuentra hasta abajo y se llama en un switch en el main, tambien quisiera cambiar el estado de las habitaciones de un struct, cuando ingresas la habitacion se actualice como ocupada =0
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
 
typedef struct Clientes
    {
        char nombre[10];
        char apellido[10];
        int habitacion;
        char fecha[10];
        int dias;
        char formaPago[10];
        char cafeteria[2];
        float costo;
    }cliente;
 
typedef struct Ocupadas         //Cuartos y disponibilidad
    {
        char estado[10];
        int disp;
        int cuarto;
    }cuartos;
 
int Hotel();
void Ingresar(cliente *reg, cuartos *room, int *cont);
void DatosResidente(cliente * reg, int *cont);
void Actualizar(cliente * reg, int cont);
void Borrar(cliente * reg, int *cont);
void Bucar(cliente * reg, int *cont);
void Habitaciones(cuartos *room);
 
int main()
{
    int opcion, respuesta, cont_reg =0;
    cliente * registros = (cliente *) malloc(20 * sizeof(cliente));
    cuartos * habitacion = (cuartos *) malloc(20 * sizeof(cuartos));
 
    do{
        system("cls");
        opcion = Hotel();
        switch(opcion)
        {
            case 1:
                Ingresar(registros, habitacion, &cont_reg);
                break;
            case 2:
                DatosResidente(registros, cont_reg);
                break;
            case 3:
                Actualizar(registros, cont_reg);
                break;
            case 4:
                Borrar(registros, &cont_reg);
                break;
            case 5:
                Buscar(registros, cont_reg);
                break;
            case 6:
                Habitaciones(habitacion);
                break;
            case 7:
                exit(1);
                break;
            default:
                printf("\nOpcion incorrecta");
                break;
        }
 
            printf("\nDesea realizar otra accion?: [1]Si  [2]No\n");
            fflush(stdin);
            scanf("\n%d",&respuesta);
 
    }while(respuesta ==1);
    free(registros);
}
int Hotel()
{
    int opcion;
    printf("HOTEL LAS PALMITAS\n");
    printf("\n[1] Ingresar datos");
    printf("\n[2] Desplegar datos");
    printf("\n[3] Actualizar estado");
    printf("\n[4] Borrar datos");
    printf("\n[5] Buscar cliente");
    printf("\n[6] Buscar habitaciones");
    printf("\n[7] Salir");
    printf("\n Seleccione la opcion: ");
    scanf("%d",&opcion);
    return opcion;
}
void Habitaciones(cuartos *room)
{
    int n;
    for(n=0;n<20;n++)
        {
            room[n].disp = 1;
            printf("\nHabitacion %2d: %d",n+1,room[n].disp);
        }
}
void Ingresar(cliente * reg, cuartos *room, int *cont)
{
    char buffer[20];
    cliente aux;
    int index;
 
    if((*cont) < 20)
    {
 
        printf("Nombre: ");
        fflush(stdin);
        fgets(aux.nombre, sizeof(buffer),stdin);
 
        printf("Apellido: ");
        fflush(stdin);
        fgets(aux.apellido, sizeof(buffer),stdin);
 
        printf("\nIngrese la habitacion deseada: ");      // Pide el cuarto deseado
        scanf("%d",&aux.habitacion);
        index = aux.habitacion;
        room[index].disp =0;
 
        printf("Fecha: ");
        fflush(stdin);
        fgets(aux.fecha, sizeof(buffer),stdin);
 
        printf("Dias: ");
        scanf("%d",&aux.dias);
 
        printf("Uso de cafeteria [Si] [No]");
        fflush(stdin);
        fgets(aux.cafeteria, sizeof(buffer),stdin);
 
 
        printf("Forma de pago: ");
        fflush(stdin);
        fgets(aux.formaPago, sizeof(buffer),stdin);
 
        reg[*cont] = aux;
        ++(*cont);
 
    }else
    {
        printf("\nNo es posible ingresar mas registros");
    }
}
void Actualizar(cliente * reg, int cont)
{
    int opcion, no_opcion, seleccion;
    char buffer[20];
    cliente aux;
    if(cont == 0){
        printf("\nNo existen datos");
    }else{
        do{
            printf("\nIngrese el registro a actualizar: ");
            scanf("%d", &opcion);
            if((opcion <0) || (opcion ==0) || (opcion>(cont))){
                printf("\nOpcion invalida, no hay datos\n");
            }else{
                printf("\nQue dato desea actualizar?");
                printf("\n[1] Nombre");
                printf("\n[2] Apellido");
                printf("\n[3] Habitacion");
                printf("\n[4] Fecha");
                printf("\n[5] Dias de estadia");
                printf("\n[6] Forma de pago");
                printf("\n[7] Salir");
                printf("\nIngrese el registro a actualizar");
                printf("\n: ");
                scanf("%d",&no_opcion);
                switch(no_opcion)
                {
                case 1:
                    printf("\nIngrese el nuevo nombre: ");
                    fflush(stdin);
                    fgets(reg[opcion-1].nombre, sizeof(buffer),stdin);
                    printf("\nDato actualizado\n");
                    break;
                case 2:
                    printf("\nIngrese el nuevo apellido: ");
                    fflush(stdin);
                    fgets(reg[opcion-1].apellido, sizeof(buffer),stdin);
                    printf("\nDato actualizado\n");
                    break;
                case 3:
                    printf("\nIngrese la nueva habitacion: ");
                    fflush(stdin);
                    scanf("%d",&reg[opcion-1].habitacion);
                    printf("\nDato actualizado\n");
                    break;
                case 4:
                    printf("\nIngrese la nueva fecha: ");
                    fflush(stdin);
                    scanf("%d",&reg[opcion-1].fecha);
                    printf("\nDato actualizado\n");
                    break;
                case 5:
                    printf("\nIngrese los nuevos dias de estadia: ");
                    fflush(stdin);
                    scanf("%d",&reg[opcion-1].dias);
                    printf("\nDato actualizado\n");
                    break;
                case 6:
                    printf("\nIngrese la nueva forma de pago");
                    fflush(stdin);
                    scanf("%d",&reg[opcion-1].formaPago);
                    printf("\nDato actualizado\n");
                    break;
                case 7:
                    exit(1);
                    break;
                default:
                    printf("\nOpcion incorrecta");
                    break;
                }
            printf("\nDesea actualizar otro dato [1]Si  [2]No");
            fflush(stdin);
            scanf("%d",&seleccion);
            }
        }while(seleccion ==1);
    }
}
void Borrar(cliente * reg, int *cont)
{
    int opcion, i;
    if((*cont)== 0)
    {
        printf("\nNo existen datos");
    }else{
        printf("\nIngrese el registro a eliminar");
        scanf("%d",&opcion);
        if((opcion <0) || (opcion ==0) || (opcion>(cont))){
            printf("\nOpcion invalida, no hay datos\n");
        }else{
            if(opcion == (*cont)){
                --(*cont);
                printf("\nEl registro fue eliminado exitosamente");
            }else{
                for(i =0; i<(*cont); ++i){
                    reg[i] = reg[i+1];
                }
                --(*cont);
                printf("\nEl registro fue eliminado exitosamente");
            }
        }
    }
}
void Buscar(cliente * reg, int cont)
{
    int opcion, respuesta;
    if(cont == 0){
        printf("\nNo existen datos");
    }else{
        do{
            system("cls");
            printf("\nIngresa el registro a buscar");
            scanf("%d",&opcion);
            if((opcion <0) || (opcion ==0) || (opcion>(cont))){
                printf("\nOpcion invalida, no hay datos\n");
            }else{
                printf("\nEste es el usuario que busco");
                printf("\nNombre: %s", reg[opcion-1].nombre);
                printf("Apellido: %s", reg[opcion-1].apellido);
 
                printf("\n Desea buscar otro usuario 1[Si]  2[No]");
                fflush(stdin);
                scanf("%d",&respuesta);
            }
        }while(respuesta !=1);
    }
}
void DatosResidente(cliente * reg, int *cont)
{
    int n;
    if(cont == 0){
        printf("\nNo hay datos de clientes");
    }else
    {
         // Imprimir datos
        printf("\n\nNombre \t   Apellido \t No.Habit \t Fecha \t    Dias rest \t  Forma de Pago \t Cafeteria \t Costo Total");
        printf("\n\n");
 
        for(n=0;n<cont;n++)
        {
            reg[n].costo =  reg[n].dias * 200;
            if(strcmp(reg[n].cafeteria,"si")==0){
                reg[n].costo += reg[n].dias * 50;
            }
            printf("%s%s",reg[n].nombre,reg[n].apellido);
            printf("%s",reg[n].apellido);
            //printf("\t %d \t %s\t %d \t  %s\t %s \t %.2f",reg[n].habitacion, reg[n].fecha,reg[n].dias, reg[n].formaPago,reg[n].cafeteria, reg[n].costo);
            //printf("\t %d \t  %s\t %s \t %.2f",reg[n].dias, reg[n].formaPago,reg[n].cafeteria, reg[n].costo);
            //printf("\t %-7s \t %-10.2f ",reg[n].cafeteria, reg[n].costo);
            //printf("\n\n");
        }
    }
}
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

Datos no se imprimen correctamente

Publicado por Nacho (181 intervenciones) el 16/10/2020 21:13:58
El salto de líonea que te imprime es el que tecleas tú al meter lo datos. Lo otro, cuando definas la estructura pon habitación a 0.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar