Ayuda con validar
Publicado por Stefania Parra (24 intervenciones) el 22/05/2019 03:11:17
Como se válida, tiene que marcar error cuando metas un número negativo, decimal y letras. Solo debe aceptar numeros positivas.
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
#include <iostream>
using namespace std;
const int N = 10;
void leerEntero( int &e )
{
do{
cin >> e;
} while( e < 0 );
}
int main()
{
int numeros[N];
int suma = 0;
cout << "Introduzca 10 numeros enteros: ";
for( int i = 0; i < 10; i++ )
leerEntero( numeros[i] );
cout << "\nLos numeros introducidos son: ";
for( int i = 0; i < 10; i++ )
cout << numeros[i] << " ";
cout << "\nLa suma de las posiciones pares es: ";
for( int i = 0; i < 10; i += 2 )
suma += numeros[i];
cout << suma;
return 0;
}
Valora esta pregunta


0