problem with define

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jul 2008
Posts: 60
Reputation: gispe is an unknown quantity at this point 
Solved Threads: 0
gispe gispe is offline Offline
Junior Poster in Training

problem with define

 
0
  #1
Sep 1st, 2008
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!


  1. // licencias.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6.  
  7. #define total_gente 20
  8.  
  9. using namespace std;
  10.  
  11.  
  12. struct datos_persona // stuff for one person
  13. {
  14. char licencia; // license
  15. int edad; //age
  16. char educacion; // education
  17. }
  18.  
  19.  
  20. void ingresar_datos (); // enter_data
  21. void ingresar_edad(); //enter age
  22. void ingresar_educacion (); // enter education
  23. 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
  24. void edades (int edades); // this is for gettin the media for ages
  25. 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
  26. void mostrar_totales_educacion (int &uni, int &tecnico, int &seccompleto, int &secincompleto); // this is for showin all the data about education
  27.  
  28.  
  29. int main(int argc, char* argv[])
  30. {
  31. int gente, uni, tecnico, seccompleto, secincompleto;
  32.  
  33.  
  34. // gente is a counter for all ppl im entering
  35. // uni means if the person has a university degree
  36. // tecnico is if the ppl did a highschool oriented to technology
  37. // seccompleto is for those who completed the highschool
  38. // secincompleto is for all ppl who didnt finish highschool
  39.  
  40.  
  41. for (gente = 0; gente < total_gente; gente++)
  42. {
  43. ingresar_datos ();
  44. ingresar_edad();
  45. ingresar_educacion();
  46. }
  47.  
  48. mostrar_totales_educacion (uni, tecnico, seccompleto, secincompleto);
  49.  
  50. system ("PAUSE");
  51.  
  52. return 0;
  53. }
  54.  
  55.  
  56.  
  57. void ingresar_datos ()
  58. {
  59. char licencia;
  60. int corredor = 0, vendedor = 0;
  61.  
  62. cout << " Ingresa el tipo de licencia que tenes: ";
  63. cout << " 1 - corredor";
  64. cout << " 2 - vendedor";
  65. cin >> licencia;
  66.  
  67.  
  68. // here i enter if the person is a runner (1)
  69. // or is a seller (2)
  70.  
  71.  
  72. if (licencia=='1')
  73. corredor++;
  74. else if (licencia=='2')
  75. vendedor++;
  76.  
  77.  
  78. // this is to sum 1 to each one im enterin
  79. }
  80.  
  81.  
  82.  
  83. void ingresar_edad()
  84. {
  85. int edad;
  86.  
  87. cout << " Ingrese su edad: \n";
  88. cin >> edad;
  89.  
  90.  
  91. // in this function i enter the age of the person
  92. // and then call the other function (edades) to get the average of all of them
  93.  
  94.  
  95. edades (edad);
  96. }
  97.  
  98.  
  99.  
  100. void ingresar_educacion ()
  101. {
  102. char educacion, licencia = 0;
  103. int corredor4, corredor3, corredor2, corredor1, vendedor4, vendedor3, vendedor2, vendedor1;
  104.  
  105. cout << " Ingrese la educacion que tiene: \n";
  106. cout << " 1 - Medio incompleto \n";
  107. cout << " 2 - Medio completo \n";
  108. cout << " 3 - Técnico completo \n";
  109. cout << " 4 - Universidad \n";
  110. cin >> educacion;
  111.  
  112.  
  113. // at this function i enter the higher education the person reached
  114. // 1 - is high school incomplete
  115. // 2 - is complete high school
  116. // 3 - is a tecnical school
  117. // 4 - university
  118.  
  119. // then call the function (totales_educacion) to sum how many ppl are in each level of education
  120.  
  121.  
  122. totales_educacion(licencia, educacion, corredor4, corredor3, corredor2, corredor1, vendedor4, vendedor3, vendedor2, vendedor1);
  123. }
  124.  
  125.  
  126.  
  127. void edades (int edades, int gente)
  128. {
  129. float prom;
  130. int edad = 0;
  131.  
  132.  
  133. // here i get the average of all ages
  134.  
  135.  
  136. edad += edad;
  137. prom = edad / gente;
  138. }
  139.  
  140. void totales_educacion(char licencia, char educacion, int &corredor4, int &corredor3, int &corredor2, int &corredor1, int &vendedor4, int &vendedor3, int &vendedor2, int &vendedor1)
  141. {
  142. int uni, tecnico, seccompleto, secincompleto;
  143.  
  144.  
  145. // in this function i get how many ppl are in every level of education
  146.  
  147. // this block of ifs are to go adding 1 to each type of license and level of education.
  148. // i have a doubt bout this, cuz dont now another way to do it if i have for exaple 10 types of licenses and
  149. // another 10 levels of education
  150.  
  151.  
  152. if ((licencia==1) && (educacion==4))
  153. corredor4++;
  154. else if ((licencia==1) && (educacion==3))
  155. corredor3++;
  156. else if ((licencia==1) && (educacion==2))
  157. corredor2++;
  158. else if ((licencia==1) && (educacion==1))
  159. corredor1++;
  160. else if ((licencia==2) && (educacion==4))
  161. vendedor4++;
  162. else if ((licencia==2) && (educacion==3))
  163. vendedor3++;
  164. else if ((licencia==2) && (educacion==2))
  165. vendedor2++;
  166. else if ((licencia==2) && (educacion==1))
  167. vendedor1++;
  168.  
  169.  
  170. // here, i get the total of each level
  171.  
  172.  
  173. uni = corredor4 + vendedor4;
  174. tecnico = corredor3 + vendedor3;
  175. seccompleto = corredor2 + vendedor2;
  176. secincompleto = corredor1 + vendedor1;
  177.  
  178.  
  179. // here i call the function to show all totals
  180.  
  181. mostrar_totales_educacion (uni, tecnico, seccompleto, secincompleto);
  182.  
  183.  
  184. // and here call the function to compare who has the highest level of education, the runners or the sellers
  185.  
  186. comparar_educacion (uni, tecnico, seccompleto, secincompleto, corredor4, corredor3, corredor2, corredor1, vendedor4, vendedor3, vendedor2, vendedor1);
  187. }
  188.  
  189.  
  190.  
  191. 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)
  192. {
  193. int total;
  194. float uni_corredor, uni_vendedor, tecnico_corredor, tecnico_vendedor, seccompleto_corredor, seccompleto_vendedor, secincompleto_corredor, secincompleto_vendedor;
  195.  
  196.  
  197. // in this function i do a percentaje for every license
  198. // also, in this function i dont know how to do it, if for example i have 20 licenses and 10 levels of education.
  199.  
  200. total = uni + tecnico + seccompleto + secincompleto;
  201.  
  202. uni_corredor = (corredor4 * 100) / total;
  203. uni_vendedor = (vendedor4 * 100) / total;
  204.  
  205. tecnico_corredor = (corredor3 * 100) / total;
  206. tecnico_vendedor = (vendedor3 * 100) / total;
  207.  
  208. seccompleto_corredor = (corredor2 * 100) / total;
  209. seccompleto_vendedor = (vendedor2 * 100) / total;
  210.  
  211. secincompleto_corredor = (corredor1 * 100) / total;
  212. secincompleto_vendedor = (vendedor1 * 100) / total;
  213.  
  214.  
  215. if (uni_corredor > uni_vendedor)
  216. cout << " Vendedor con mayor nivel universitario";
  217. else if (tecnico_corredor > tecnico_vendedor)
  218. cout << " Vendedor con mayor nivel universitario";
  219. else if (seccompleto_corredor > seccompleto_vendedor)
  220. cout << " Vendedor con mayor nivel universitario";
  221. else if ()
  222.  
  223. }
  224.  
  225. void mostrar_totales_educacion (int &uni, int &tecnico, int &seccompleto, int &secincompleto)
  226. {
  227. cout << "Total por universidad: " << uni;
  228. cout << "Total por tecnico: " << tecnico;
  229. cout << "Total por secundario completo: " << seccompleto;
  230. cout << "Total por secundario incompleto: " << secincompleto;
  231. }


thanks!!
gispe!!
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,678
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 193
vmanes's Avatar
vmanes vmanes is online now Online
Posting Virtuoso

Re: problem with define

 
0
  #2
Sep 1st, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: problem with define

 
0
  #3
Sep 1st, 2008
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...
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 60
Reputation: gispe is an unknown quantity at this point 
Solved Threads: 0
gispe gispe is offline Offline
Junior Poster in Training

Re: problem with define

 
0
  #4
Sep 1st, 2008
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..
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 60
Reputation: gispe is an unknown quantity at this point 
Solved Threads: 0
gispe gispe is offline Offline
Junior Poster in Training

Re: problem with define

 
0
  #5
Sep 1st, 2008
yes, i know, but they asked to use a struct
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,678
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 193
vmanes's Avatar
vmanes vmanes is online now Online
Posting Virtuoso

Re: problem with define

 
0
  #6
Sep 1st, 2008
Originally Posted by gispe View Post
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.
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: problem with define

 
0
  #7
Sep 1st, 2008
Originally Posted by gispe View Post
yes, i know, but they asked to use a struct
Exactly! Think about an array (or vector) of structures.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC