RSS Forums RSS

problem with counter

Please support our C++ advertiser: Programming Forums
Reply
Posts: 49
Reputation: gispe is an unknown quantity at this point 
Solved Threads: 0
gispe gispe is offline Offline
Light Poster

problem with counter

  #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. }
  41.  
AddThis Social Bookmark Button
Reply With Quote  
Posts: 2,000
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: 331
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: problem with counter

  #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  
Posts: 49
Reputation: gispe is an unknown quantity at this point 
Solved Threads: 0
gispe gispe is offline Offline
Light Poster

Re: problem with counter

  #3  
Jul 25th, 2008
so, replacing that, ill have the top seller, and then the ppl who follow him, right?
Reply With Quote  
Posts: 2,000
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: 331
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: problem with counter

  #4  
Jul 26th, 2008
Well, try it then post...
Reply With Quote  
Posts: 49
Reputation: gispe is an unknown quantity at this point 
Solved Threads: 0
gispe gispe is offline Offline
Light Poster

Re: problem with counter

  #5  
Jul 26th, 2008
tested it n work!
thanks!!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Views: 377 | Replies: 4 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 1:24 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC