# Sum of positions of a cycle for c

2

I made a program using functions in which you requested the age of the person, and added some conditions that if it is less than 12 years old it is childish and the cost is 300, if it is less than 18 years old it is considered childish and the cost is 500 and if it is over 18 years it is considered adult and the cost is 800. The program allows the entry of 10 people, however, I am not adding the positions I want for each condition, what I need is print how many people entered each category but it is not working the right way. Excuse me if you do not explain well.

``````#include <stdlib.h>
#include <conio.h>
#include <time.h>
#include <stdio.h>

void main ()
{
int x,y,r;

printf ("BIENVENIDOS AL EVENTO\n");

{
}
for (x=0;x<=9;x++)
{
}

printf ("El total de los boletos es de %d",r);
}

void evento (int edad[]) //Recibe funcion
{
int suma=0, suma2=0, suma3=0;
int i,o = 300,x,h = 500,t = 800,p,q;

for (i=0; i < 10;i++) // Suma las posiciones que son menor a 13, aqui es donde no me esta dando, igual que en las otras condiciones.

{
{
suma = suma+i;
}
}
printf ("En infantil ingresaron %d personas\n",suma);

for (i=0;i<10;i++)  // Suma las posiciones que son menor a 18
{
{
suma2 = suma2+i;
}
}
printf ("En juvenil ingresaron %d personas\n",suma2);

for (i=0;i< 10;i++)   // Suma las posiciones que son mayor a 18
{
{
suma3=suma3+i;
}
}

//q=h+o+t;
//return q;
}
``````

asked by Arturo 10.08.2018 в 01:07
source

1

Reading a bit I think that what you need is just to add the number of people for each category and not the costs of each ticket, then it would be like this:

``````#include <stdlib.h>
#include <conio.h>
#include <time.h>
#include <stdio.h>

void main ()
{
int x,r;

printf ("BIENVENIDOS AL EVENTO\n");

{
}
for (x=0;x<=9;x++)
{
}

printf ("El total de los boletos es de %d",r);
}

void evento (int edad[]) //Recibe funcion
{
int sumas=0;
int sumas1=0;
int sumas2=0;
int j,k,q;

// con un solo ciclo recorremos todo el arreglo y discriminamos por categoria
for (j=0; j < 10;j++) // Suma las posiciones que son menor a 13
{
{
sumas = sumas+1;
}
else
{
sumas1 = sumas1+1;//alamacenamos la suma de cada persona que son menor a 18

}
else
{
sumas2 = sumas2+1;// alamacenamos la suma de cada persona que son mayor a 18
}
}

printf ("En infantil ingresaron %d personas\n",sumas);

printf ("En juvenil ingresaron %d personas\n",sumas1);

printf ("En adultos ingresaron %d personas\n",sumas2);

q=1*k;
return q;
}
``````

NOTE If you want to add the values of each ticket, it would also be the same ...

I hope you serve and marques xD ... ReNiceCode ...