ayudenme con mi codigo no se que estoy haciendo mal se supone que al validar la fecha si introduces una fecha mal ya no deberia funcionar pero al parecer solo valida el mes ayuda, tambien necesito ayuda para apuntar a un elemento del arreglo
char claveHabitacion [10][10] = {"ST1", "ST2", "ST3", "ST4", "ST5", "ST6", "ST7", "ST8", "ST9", "ST10"}; no se como hacerlo.
#include<stdio.h>
#include<stdlib.h>
#include <stdbool.h>
struct fechaEntrada
{
int dia, mes, año;
}f1;
struct fechaSalida
{
int dia, mes, año;
}f2;
struct tarjeta{
int cVc, tipo, formaPago;
char nombreTitular[50];
int mes, año;
}t1;
bool entrada(int dia, int mes, int año)
{
bool verdero=1, falso=0;
printf("\nIntroduzca la fecha de entrada: ");
printf( "\n Introduzca dia: ");
scanf( "%d", &f1.dia );
printf( "\n Introduzca mes: " );
scanf( "%d", &f1.mes );
printf( "\n Introduzca año: ");
scanf( "%d", &f1.año );
if ( f1.mes >= 1 && f1.mes <= 12 )
{
switch ( f1.mes )
{
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10 :
case 12 : if ( f1.dia >= 1 && f1.dia <= 31 )
{
printf( "\n FECHA CORRECTA \n" , verdero);
return verdero;
} else
printf( "\n FECHA INCORRECTA \n", falso);
return falso;
break;
case 4 :
case 6 :
case 9 :
case 11 : if ( f1.dia >= 1 && f1.dia <= 30 )
{
printf( "\n FECHA CORRECTA \n", verdero );
return verdero;
}else
printf( "\n FECHA INCORRECTA \n", falso);
return falso;
break;
case 2 : if( f1.año % 4 == 0 && f1.año % 100 != 0 || f1.año % 400 == 0 ){
if ( f1.dia >= 1 && f1.dia <= 29 )
{
printf( "\n FECHA CORRECTA \n", verdero);
return verdero;
}else
printf( "\n FECHA INCORRECTA \n", falso);
return falso;
}else
if ( f1.dia >= 1 && f1.dia <= 28 )
{
printf( "\n FECHA CORRECTA \n", verdero);
return verdero;
}else
printf( "\n FECHA INCORRECTA \n", falso);
return falso;
}
}
else
printf( "\n FECHA INCORRECTA \n", falso);
}
bool salida(int dia, int mes, int año)
{
bool verdero=1, falso=0;
printf("\nIntroduzca la fecha de salida: ");
printf( "\n Introduzca dia: ");
scanf( "%d", &f2.dia );
printf( "\n Introduzca mes: " );
scanf( "%d", &f2.mes );
printf( "\n Introduzca año: ");
scanf( "%d", &f2.año );
if ( f2.mes >= 1 && f2.mes <= 12 )
{
switch ( f2.mes )
{
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10 :
case 12 : if ( f2.dia >= 1 && f2.dia <= 31 )
{
printf( "\n FECHA CORRECTA \n" , verdero);
return verdero;
} else
printf( "\n FECHA INCORRECTA \n", falso);
return falso;
break;
case 4 :
case 6 :
case 9 :
case 11 : if ( f2.dia >= 1 && f2.dia <= 30 )
{
printf( "\n FECHA CORRECTA \n", verdero );
return verdero;
}else
printf( "\n FECHA INCORRECTA \n", falso);
return falso;
break;
case 2 : if( f2.año % 4 == 0 && f2.año % 100 != 0 || f2.año % 400 == 0 ){
if ( f2.dia >= 1 && f2.dia <= 29 )
{
printf( "\n FECHA CORRECTA \n", verdero);
return verdero;
}else
printf( "\n FECHA INCORRECTA \n", falso);
return falso;
}else
if ( f2.dia >= 1 && f2.dia <= 28 )
{
printf( "\n FECHA CORRECTA \n", verdero);
return verdero;
}else
printf( "\n FECHA INCORRECTA \n", falso);
return falso;
}
}
else
printf( "\n FECHA INCORRECTA \n", falso);
return falso;
}
void reservacionStandard()
{
int i=0, x=0;
long long numeroTarjeta=9999999999999999;
char claveHabitacion [10][10] = {"ST1", "ST2", "ST3", "ST4", "ST5", "ST6", "ST7", "ST8", "ST9", "ST10"};
printf("\n Introduce tu forma de pago \n 1.-Tarjeta \n 2.-Efectivo \n");
scanf("%d", &t1.formaPago);
printf("\n Introduce el numero de tarjeta: \n");
scanf("%d", &numeroTarjeta);
while(numeroTarjeta > 0)
{
numeroTarjeta = numeroTarjeta / 10;
i++;
}
//printf("%d", i);
if( i == 16)
{
printf("\nIntroduce el nombre del titular de la tarjeta: \n");
scanf("%s", &t1.nombreTitular);
printf("\nIntroduce el mes de vencimiento: \n ");
scanf("%d", &t1.mes);
printf("\nIntroduce el año de vencimiento: \n ");
scanf("%d", &t1.año);
if( t1.mes >= 1 && t1.mes <= 12 )
{
if(t1.año >= 2019 && t1.año <= 2026)
{
printf("\n Introduce el CVC: \n");
scanf("%d", &t1.cVc);
while(t1.cVc > 0)
{
t1.cVc = t1.cVc / 10;
x++;
}
if(x == 3)
{
printf("\n Estas son las habitaciones disponibles: \n");
for(i=0; i < 10 ; i++)
{
for(int j=0; j < 10; j++)
{
printf("%c", claveHabitacion[j]);
}
printf("\n");
}
}else
printf("\n El CVC no es correcto \n");
} else
printf("\n año incorrecto intenta de nuevo \n");
}
else
printf("\n mes incorrecto intenta de nuevo \n");
} else
printf("\nTarjeta No valida \n");
}
int main(){
int op, o1, dia1, mes1, anio1, eleccion, cantidadPersonas, cantidadNoches, costo;
do
{
printf("Hotel h&h");
printf("\n1.-Reservaciones \n 2.-Cancelaciones \n 3.-Reportes \n 4.-Terminar \n");
scanf("%d", &op);
switch(op)
{
case 1:
if(entrada(dia1, mes1, anio1) == 1)
{
if(salida(dia1, mes1, anio1) == 1)
{
cantidadNoches= ((f2.año-f1.año)*12 +(f2.mes-f1.mes))*30 + f2.dia- f1.dia;
costo = cantidadNoches*1250;
printf("\nLa cantidad de noches es: %d", cantidadNoches);
printf(" \nElige el tipo de habitacion : \n 1.-ST \n 2.-OB \n 3.-TB \n 4.-SU \n");
scanf("%d", &eleccion);
printf("\nEl costo total es: $%d \n", costo);
switch(eleccion)
{
case 1: printf("\nIntroduce cuantas personas ocuparan la habitacion: ");
scanf("%d", &cantidadPersonas);
if(cantidadPersonas <=2 )
{
reservacionStandard(costo);
}
}
}
}
break;
case 2:
break;
case 3:
do
{
printf("Hotel h&h");
printf("\n1.-Reporte de reservaciones \n 2.- Reporte de habitaciones disponibles \n 3.-Regresar \n");
scanf("%d", &o1);
switch(o1)
{
case 1:
break;
case 2:
break;
}
}while(o1 < 3);
break;
}
}while(op < 4);
return 0;
}
Hola una de las formas de cotejar el dia seria asi por ejemplo
#include <stdio.h>
int cotejar_dia(int, int, int[7]);
int main()
{
int dia, mes;
int mes_31[7]={1, 3, 5, 7, 8, 10, 12};
long año[2999];
printf("introduce el dia y el mes");
scanf("%i %i", &dia, &mes);
if(cotejar_dia(dia, mes, mes_31))
printf("correcto");
else
printf("Incorrecto");
printf("\n");
return 0;
}
int cotejar_dia(int dia, int mes, int mes_31[7])
{
int i;
int low = 1;
int high = 31;
for(i = 0; i < 7; i++)
{
if(dia >=low && dia <=high && mes == mes_31[i])
return 1;
}
return 0;
}
int i;
para apuntar al elemento de un arreglo seria *(elemento + i)
Dejo por aquí otra función que permite validar una fecha :-X
bool validarFecha(int day, int month, int year){
int dias_mes[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
if(month < 1 or month > 12)
return false;
if(month == 2 and esBisiesto(year))
dias_mes[1] = 29;
return day <= dias_mes[month-1];
}
bool esBisiesto(int year){
return (year % 4 == 0 && (!(year % 100 == 0) || (year % 400 == 0)))
}