How to do cellular and date validation in a C++ application

Asked

Viewed 33 times

0

Hello, I am a beginner and I have an activity to do, I need the following steps:

. In the cellular attribute, it is necessary to validate the input so that numbers are accepted within the range 900000000 to 999999999 only, and if the number is outside this range, ask for new typing. . Also validate the typing of the day of the month in an interval of 1 to 31 only, as well as month between 1 and 12, and finally, year between 1900 and 2021, reducing the chances of inappropriate data entries for each variable, and in case of failure in any of the three data, request new entry

i’ve already done a part but these validations I’m not able to do, the activity is for Friday and I’m running out of time. follow down my code

#include <stdio.h>
#include <locale.h>

typedef struct {
    char nome[3];

    int celular;

    int diaN;

    int mesN;

    int anoN;

} 
dados;


int main (){


    int i, j;

    long long dig1, dig2, aux;

    dados y[3];

    setlocale(LC_ALL, "");

    for (i=0; i<3; i++){

        printf ("\n*** Cadastro %d ***\n", i+1);
        
        printf ("Nome: ");
        scanf (" %s", y[i].nome);
        
        
        
        
        printf ("Celular: ");
        scanf ("%d", &y[i].celular);
        
        
        
        
        printf ("Data de Nascimento (dia): ");
        scanf ("%d", &y[i].diaN);
        
        
        
        printf ("Data de Nascimento (mês): ");
        scanf ("%d", &y[i].mesN);
    
        
        
        
        printf ("Data de Nascimento (ano): ");
        scanf ("%d", &y[i].anoN);
   
    printf ("\n\n*** CONSULTA NO CADASTRO ***\n");
    printf ("Escolha uma posição a exibir (1 a 3): ");
    scanf ("%d", &i);
    printf ("Nome: %s\n", y[i-1].nome);
    printf ("Celular: %d\n", y[i-1].celular);
    printf ("Data de Nascimento: %d/%d/%d\n", y[i-1].diaN);
}
}
  • "I’ve already done a part but these validations I’m not able to do" - in what part of the code are these validations ?

  • i tried to do the validation inside the for, open an if condition but it does not enter the condition, it is not in that code I posted, my error

  • technically would look like this if (Dian=0 & Dian<=3)' printf(") }

  • do not use int for these values. will not operate with them. It will only get harder so

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.