problem with counter

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

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

problem with counter

 
0
  #1
Jul 25th, 2008
hi ppl
im back here, but with another problem in another code.
in this one i have to count how many sellers reached the top sells.
thing is that if i put one that reached the top at the end, the program doesnt count it, it counts only the first ones before the last one.
i mean, for example, i put:

code of employee = 1
sells = 20

code of employee = 2
sells = 10

code of employee = 3
sells = 20

code of employee = 0


the code of employee = 3
sells = 20
doesnt count

shall i use a for loop instead?? or a for loop inside the while loop, just to count the employees who reach that top??

  1. // maximo_ventas.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6.  
  7.  
  8. int main(int argc, char* argv[])
  9. {
  10. using namespace std;
  11.  
  12. int legajo, vendedor = 0;
  13. float ventas_vendedor, aux_ventas = 0;
  14.  
  15. cout << " Ingrese legajo del vendedor: "; //code of employee, number wich i use to identify him
  16. cin >> legajo;
  17. cout << "\n";
  18.  
  19. while (legajo != 0)
  20. {
  21. cout << "Ingrese importe total de ventas de ese vendedor: ";
  22. cin >> ventas_vendedor;
  23. cout << "\n";
  24.  
  25. while (ventas_vendedor > aux_ventas) // here i have the max sells made
  26. {
  27. aux_ventas = ventas_vendedor;
  28. vendedor +=1; // here i count the people who reached that.
  29. }
  30.  
  31. cout << " Ingrese legajo del vendedor: ";
  32. cin >> legajo;
  33. cout << "\n";
  34. }
  35.  
  36. cout << " El maximo de ventas fue: " << aux_ventas << "\n";
  37. cout << " El total de vendedores que alcanzaron ese maximo fue: " << vendedor << "\n";
  38.  
  39. return 0;
  40. }
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 counter

 
0
  #2
Jul 25th, 2008
You have absolutely useless inner while loop. Replace it:
  1. if (ventas_vendedor > aux_ventas) // here i have the max sells made
  2. {
  3. aux_ventas = ventas_vendedor;
  4. vendedor = 1; // Now we have one and only one leader!
  5. }
  6. else if (ventas_venderor == aux_ventas)
  7. ++vendedor; // addition to the family...
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 59
Reputation: gispe is an unknown quantity at this point 
Solved Threads: 0
gispe gispe is offline Offline
Junior Poster in Training

Re: problem with counter

 
0
  #3
Jul 25th, 2008
so, replacing that, ill have the top seller, and then the ppl who follow him, right?
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 counter

 
0
  #4
Jul 26th, 2008
Well, try it then post...
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 59
Reputation: gispe is an unknown quantity at this point 
Solved Threads: 0
gispe gispe is offline Offline
Junior Poster in Training

Re: problem with counter

 
0
  #5
Jul 26th, 2008
tested it n work!
thanks!!
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