| | |
problem with define
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jul 2008
Posts: 60
Reputation:
Solved Threads: 0
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!
thanks!!
gispe!!
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!
C++ Syntax (Toggle Plain Text)
// 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!!
So, what's your question?
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
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...
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..
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.
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
![]() |
Similar Threads
- PROBLEM WITH #define (C++)
- Website problem (ASP)
- Learning PHP but problem with script (PHP)
- Samba Access Problem (*nix Software)
- I have problem with deep copy (C++)
- Multithreading problem (C)
- TO CHAINSAW - or anybody else who knows C++ (C++)
- Stack Queue Fstream (C++)
- ** Need Help ** in a small C++ problem (C++)
Other Threads in the C++ Forum
- Previous Thread: One of the sound commands
- Next Thread: program fail!
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion count data delete deploy desktop developer directshow dll download dynamic encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node number output parameter pointer problem program programming project proxy python read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






