View Single Post
Join Date: Jul 2008
Posts: 58
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