User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 401,421 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,915 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 136 | Replies: 4
Reply
Join Date: Jul 2008
Posts: 47
Reputation: gispe is an unknown quantity at this point 
Rep Power: 0
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  
Join Date: Jul 2008
Posts: 369
Reputation: ArkM has a spectacular aura about ArkM has a spectacular aura about ArkM has a spectacular aura about 
Rep Power: 3
Solved Threads: 57
ArkM ArkM is offline Offline
Posting Whiz

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  
Join Date: Jul 2008
Posts: 47
Reputation: gispe is an unknown quantity at this point 
Rep Power: 0
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  
Join Date: Jul 2008
Posts: 369
Reputation: ArkM has a spectacular aura about ArkM has a spectacular aura about ArkM has a spectacular aura about 
Rep Power: 3
Solved Threads: 57
ArkM ArkM is offline Offline
Posting Whiz

Re: problem with counter

  #4  
Jul 26th, 2008
Well, try it then post...
Reply With Quote  
Join Date: Jul 2008
Posts: 47
Reputation: gispe is an unknown quantity at this point 
Rep Power: 0
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.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 12:23 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC