hi ppl,
im having a problem with this program.
The thing is that i need to enter the license, age and level of education of an amount of ppl, but dont know how many.
then i have to get the percentaje of runners and sellers, the average age, amount of ppl acording to education level, and who have the highest level of education (runners or sellers).
the code is below with some comments explaining it.
if dont understand something, just ask!

// licencias.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

#define total_gente 20

using namespace std;


struct datos_persona     // stuff for one person
{ 
	char licencia;    // license
	int edad;         //age
	char educacion;   // education
}


void ingresar_datos ();   // enter_data
void ingresar_edad();     //enter age
void ingresar_educacion ();     // enter education
void totales_educacion(char licencia, char educacion, int &corredor4, int &corredor3, int &corredor2, int &corredor1, int &vendedor4, int &vendedor3, int &vendedor2, int &vendedor1);   // totals of education
void edades (int edades);  // this is for gettin the media for ages
void comparar_educacion (int &uni, int &tecnico, int &seccompleto, int &secincompleto, int corredor4, int corredor3, int corredor2, int corredor1, int vendedor4, int vendedor3, int vendedor2, int vendedor1); // this is to get the max average of education
void mostrar_totales_educacion (int &uni, int &tecnico, int &seccompleto,  int &secincompleto); // this is for showin all the data about education
 

int main(int argc, char* argv[])
{
	int gente, uni, tecnico, seccompleto,  secincompleto;


// gente is a counter for all ppl im entering
// uni means if the person has a university degree
// tecnico is if the ppl did a highschool oriented to technology
// seccompleto is for those who completed the highschool
// secincompleto is for all ppl who didnt finish highschool


	for (gente = 0; gente < total_gente; gente++)
	{
		ingresar_datos ();
		ingresar_edad();
		ingresar_educacion();
	}
 
	mostrar_totales_educacion (uni, tecnico, seccompleto,  secincompleto);
	
	system ("PAUSE");
	
	return 0;
}
 


void ingresar_datos ()
{
	char licencia;
	int corredor = 0, vendedor = 0;

	cout << " Ingresa el tipo de licencia que tenes: ";
	cout << "    1 - corredor";
	cout << "    2 - vendedor";
	cin >> licencia;


// here i enter if the person is a runner (1)
// or is a seller (2)

	
	if (licencia=='1')
		corredor++;
	else if (licencia=='2')
		vendedor++;


// this is to sum 1 to each one im enterin
}
 


void ingresar_edad()
{
	int edad;
	
	cout << " Ingrese su edad: \n";
	cin >> edad;


// in this function i enter the age of the person
// and then call the other function (edades) to get the average of all of them


	edades (edad);
}
 


void ingresar_educacion ()
{
	char educacion, licencia = 0;
	int corredor4, corredor3, corredor2, corredor1, vendedor4, vendedor3, vendedor2, vendedor1;
 
	cout << " Ingrese la educacion que tiene:  \n";
	cout << "     1 - Medio incompleto \n"; 
	cout << "     2 - Medio completo \n";
	cout << "     3 - Técnico completo \n";
	cout << "     4 - Universidad \n";
	cin >> educacion;


// at this function i enter the higher education the person reached
// 1 - is high school incomplete
// 2 - is complete high school
// 3 - is a tecnical school
// 4 - university

// then call the function (totales_educacion) to sum how many ppl are in each level of education


	totales_educacion(licencia, educacion, corredor4, corredor3, corredor2, corredor1, vendedor4, vendedor3, vendedor2, vendedor1);
}
 


void edades (int edades, int gente)
{
	float prom;
	int edad = 0;


// here i get the average of all ages


	edad += edad;
	prom = edad / gente;
}

void totales_educacion(char licencia, char educacion, int &corredor4, int &corredor3, int &corredor2, int &corredor1, int &vendedor4, int &vendedor3, int &vendedor2, int &vendedor1)
{
	int uni, tecnico, seccompleto, secincompleto;


// in this function i get how many ppl are in every level of education

// this block of ifs are to go adding 1 to each type of license and level of education.
// i have a doubt bout this, cuz dont now another way to do it if i have for exaple 10 types of licenses and
// another 10 levels of education 


	if ((licencia==1) && (educacion==4))
		corredor4++;
	else if ((licencia==1) && (educacion==3))
		corredor3++;
	else if ((licencia==1) && (educacion==2)) 
		corredor2++;
	else if ((licencia==1) && (educacion==1))
		corredor1++;
	else if ((licencia==2) && (educacion==4))
		vendedor4++;
	else if ((licencia==2) && (educacion==3))
		vendedor3++;
	else if ((licencia==2) && (educacion==2))
		vendedor2++;
	else if ((licencia==2) && (educacion==1))
		vendedor1++;


// here, i get the total of each level


	uni = corredor4 + vendedor4;
	tecnico = corredor3 + vendedor3;
	seccompleto = corredor2 + vendedor2;
	secincompleto = corredor1 + vendedor1;
	

// here i call the function to show all totals

	mostrar_totales_educacion (uni, tecnico, seccompleto,  secincompleto);


//	and here call the function to compare who has the highest level of education, the runners or the sellers

	comparar_educacion (uni, tecnico, seccompleto, secincompleto, corredor4, corredor3, corredor2, corredor1, vendedor4, vendedor3, vendedor2, vendedor1);
}



void comparar_educacion (int &uni, int &tecnico, int &seccompleto, int &secincompleto, int corredor4, int corredor3, int corredor2, int corredor1, int vendedor4, int vendedor3, int vendedor2, int vendedor1)
{
	int total;
	float uni_corredor, uni_vendedor, tecnico_corredor, tecnico_vendedor, seccompleto_corredor, seccompleto_vendedor, secincompleto_corredor, secincompleto_vendedor;


// in this function i do a percentaje for every license
// also, in this function i dont know how to do it, if for example i have 20 licenses and 10 levels of education.

	total = uni + tecnico + seccompleto + secincompleto;

	uni_corredor = (corredor4 * 100) / total;
	uni_vendedor = (vendedor4 * 100) / total;

	tecnico_corredor = (corredor3 * 100) / total;
	tecnico_vendedor = (vendedor3 * 100) / total;

	seccompleto_corredor = (corredor2 * 100) / total;
	seccompleto_vendedor = (vendedor2 * 100) / total;

	secincompleto_corredor = (corredor1 * 100) / total;
	secincompleto_vendedor = (vendedor1 * 100) / total;


	if (uni_corredor > uni_vendedor)
		cout << " Vendedor con mayor nivel universitario";
	else if (tecnico_corredor > tecnico_vendedor)
		cout << " Vendedor con mayor nivel universitario";
	else if (seccompleto_corredor > seccompleto_vendedor)
		cout << " Vendedor con mayor nivel universitario";
	else if ()

}
 
void mostrar_totales_educacion (int &uni, int &tecnico, int &seccompleto,  int &secincompleto)
{
	cout << "Total por universidad: " << uni; 
	cout << "Total por tecnico: " << tecnico;
	cout << "Total por secundario completo: " << seccompleto;
	cout << "Total por secundario incompleto: " << secincompleto;
}

thanks!!
gispe!!

Recommended Answers

All 6 Replies

So, what's your question?

It seems you have never seen such basic C++ construct as an array.
Please, take your text-book on programming then search and study "An array" part.
After that you will never write functions with v1, v2, v3, v4 and so on parameters.
Moreover, you will never invent the only global struct and horrible ifs cascade to solve so simple problem...

my question is how can i do to make the part to compare the max if dont know how many i have of any of them..

yes, i know, but they asked to use a struct :S

my question is how can i do to make the part to compare the max if dont know how many i have of any of them..

You store a copy of the very first value read in to your max_value variable.
As you read in every other data item, compare it to max_value. If the new value is greater, store that to max_value.

This works if you have just one input, or a billion. You don't need to know how many there will be.

yes, i know, but they asked to use a struct :S

Exactly! Think about an array (or vector) of structures.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.