943,610 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 544
  • C++ RSS
Jul 25th, 2008
0

problem with counter

Expand Post »
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??

C++ Syntax (Toggle Plain Text)
  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. }
Similar Threads
Reputation Points: 6
Solved Threads: 0
Junior Poster in Training
gispe is offline Offline
74 posts
since Jul 2008
Jul 25th, 2008
0

Re: problem with counter

You have absolutely useless inner while loop. Replace it:
C++ Syntax (Toggle Plain Text)
  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...
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008
Jul 25th, 2008
0

Re: problem with counter

so, replacing that, ill have the top seller, and then the ppl who follow him, right?
Reputation Points: 6
Solved Threads: 0
Junior Poster in Training
gispe is offline Offline
74 posts
since Jul 2008
Jul 26th, 2008
0

Re: problem with counter

Well, try it then post...
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008
Jul 26th, 2008
0

Re: problem with counter

tested it n work!
thanks!!
Reputation Points: 6
Solved Threads: 0
Junior Poster in Training
gispe is offline Offline
74 posts
since Jul 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Pls help me... in array problem..
Next Thread in C++ Forum Timeline: Library function





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC