-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.c
55 lines (52 loc) · 1.39 KB
/
utils.c
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
#include "utils.h"
int obtenerEnteroPositivo()
{
int numero, error = 0;
do
{
if(error != 0)
{
printf("\n\nNumero incorrecto. Recuerde que debe ser mayor o igual a cero.");
error = 0;
}
printf("\n\n\nIngrese un numero mayor a cero: ");
scanf("%d", &numero);
if(numero < 0) error = 1;
}
while(numero < 0);
return numero;
}
int obtenerNumeroMayorOIgualA(int numero)
{
int numeroMayor, error = 0;
do
{
if(error != 0)
{
printf("\n\nNumero incorrecto. Recuerde que debe ser mayor o igual a %d.", numero);
error = 0;
}
printf("\n\n\nIngrese un numero mayor a %d: ", numero);
scanf("%d", &numeroMayor);
if(numeroMayor < numero) error = 1;
}
while(numeroMayor < numero);
return numeroMayor;
}
int obtenerNumeroEntre(int numeroUno, int numeroDos)
{
int numeroEntre, error = 0;
do
{
if(error != 0)
{
printf("\n\nNumero incorrecto. Recuerde que debe estar entre %d y %d.", numeroUno, numeroDos);
error = 0;
}
printf("\n\n\nIngrese entre %d y %d: ", numeroUno, numeroDos);
scanf("%d", &numeroEntre);
if(numeroEntre < numeroUno || numeroEntre > numeroDos) error = 1;
}
while(numeroEntre < numeroUno || numeroEntre > numeroDos);
return numeroEntre;
}