How could the user enter the following data only on a line not as in the code and validate it?

0
do{
    do{
        printf("Punto 1 A\n"); //X1
            scanf("%d",&a1);
            if(a1<0 || a1>10000)
            {
                printf("\nError el Numero Debe ser mayor a 0 y menor a 10.000\n");
            }
    }while(a1<0 || a1>10000);

    do{
        printf("Punto 2 A\n"); // Y1
            scanf("%d",&a2);
            if(a2<0 || a2>10000)
            {
                printf("Error el Numero Debe ser mayor a 0 y menor a 10.000\n");
            }
    }while(a2<0 || a2>10000);

    do{
        printf("Punto 1 B\n"); //X2
            scanf("%d",&b1);
            if(b1<0 || b1>10000)
            {
                printf("Error el Numero Debe ser mayor a 0 y menor a 10.000\n");
            }
    }while(b1<0 || b1>10000);

    do{
        printf("Punto 2 B\n"); //Y2
            scanf("%d",&b2);
            if(b2<0 || b2>10000)
            {
                printf("Error el Numero Debe ser mayor a 0 y menor a 10.000\n"); 
            }
    }while(b2<0 || b2>10000);
    
asked by Jors 24.07.2018 в 23:47
source

2 answers

0

Sorry, I do not understand your question well. What do you want to do is enter a1, a2, b1 and b2 in the same line and without validating?

If that is the case, it would be enough to do the following:

  • scanf ("% d% d% d% d", & a1, & a2, & b1, & b2);

Try to enter a space between each element entered so that it is stored in the following variable.

I hope it serves you and if it is not, I apologize.

    
answered by 30.07.2018 в 02:18
0

. If you have defined the amount of values, you could ask for them in a vector through a for cycle. Create a function where you capture and validate your data (I see that the condition for all is the same) so you save several lines of code.

    
answered by 30.07.2018 в 05:36