DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   problem with counter (http://www.daniweb.com/forums/thread136782.html)

gispe Jul 25th, 2008 5:31 pm
problem with counter
 
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??

// maximo_ventas.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>


int main(int argc, char* argv[])
{
        using namespace std;

        int legajo, vendedor = 0;
        float ventas_vendedor, aux_ventas = 0;

        cout << " Ingrese legajo del vendedor: ";    //code of employee, number wich i use to identify him
        cin >> legajo;
        cout << "\n";

        while (legajo != 0)   
        {
                cout << "Ingrese importe total de ventas de ese vendedor: ";
                cin >> ventas_vendedor;
                cout << "\n";

                while (ventas_vendedor > aux_ventas)    // here i have the max sells made
                {
                        aux_ventas = ventas_vendedor;
                        vendedor +=1;    // here i count the people who reached that.
                }

                cout << " Ingrese legajo del vendedor: ";
                cin >> legajo;
                cout << "\n";
        }

        cout << " El maximo de ventas fue: " << aux_ventas << "\n";
        cout << " El total de vendedores que alcanzaron ese maximo fue: " << vendedor << "\n";

        return 0;
}

ArkM Jul 25th, 2008 6:10 pm
Re: problem with counter
 
You have absolutely useless inner while loop. Replace it:
if (ventas_vendedor > aux_ventas)    // here i have the max sells made        
{
    aux_ventas = ventas_vendedor;
    vendedor = 1;    // Now we have one and only one leader!
}
else if (ventas_venderor == aux_ventas)
    ++vendedor;    // addition to the family...

gispe Jul 25th, 2008 7:38 pm
Re: problem with counter
 
so, replacing that, ill have the top seller, and then the ppl who follow him, right?

ArkM Jul 26th, 2008 1:37 am
Re: problem with counter
 
Well, try it then post...

gispe Jul 26th, 2008 12:21 pm
Re: problem with counter
 
tested it n work!
thanks!!


All times are GMT -4. The time now is 6:24 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC