Jun 5, 2016 at 4:50am UTC
Create a menu with the following
options:
1. Generate 10 random numbers
between 1 and 15 and stored in an array, add only the even positions.
Using functions not receive and return.
2. Capture keyboard numerical values that are greater than 0, for a 3 by 4 matrix, show the sum of the values in each row. Using functions do not get no return.
Thanks for the help
Jun 5, 2016 at 5:29am UTC
I have advanced to the first point but I find this error: [Error] 'Math' was not esta Declared in scope.
The code goes like this:
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
#include<iostream>
#include<stdio.h>
using namespace std;
void pares(int arreg[]);
void mayor(int arreg[]);
void promedio_arreglo();
int menu();
float suma;
int main()
{
int arreglo[10];
int opcion;
pares(arreglo);
printf("\nQue desea hacer: " );
do
{
opcion = menu();
switch (opcion)
{
case 1:
pares(arreglo);
break ;
case 2:
mayor(arreglo);
printf("\nLa suma del arreglo es %d\n" , suma);
break ;
default :
if (opcion != 6)
{
printf("\nEl numero %d no es una opcion valida.\nPro favor introduzca otro numero.\n" , opcion);
}
}
}while (opcion != 6);
printf("\nHASTA LUEGO" );
return 0;
}
int menu()
{
int seleccion;
printf("\n\t1.\tpares" );
printf("\n\t2.\tmayor" );
printf("\n\t6.\tSalir." );
printf("\n\t\tElija una opcion por favor: " );
scanf("%d" , &seleccion);
return seleccion;
}
void pares(int arreg[])
{
int arreglo[10];
int sum=0;
for (int i = 0; i < 10; i++)
arreglo[i]=(int ) (Math.random()*(15-1+1) + 1)
{
cout<<i;
if (i%2==0)
sum=sum+arreglo[i];
}
cout<<sum;
}
Last edited on Jun 5, 2016 at 5:30am UTC
Jun 6, 2016 at 10:43am UTC
Nowhere in your code is there any definition of Math . What is it supposed to be?