hi!!
i made a program to count the max sales in a store, that has for example 10 employees.
for this, i used an struct to have the code of the employee and the sales he made. the point of the code is to show a list of the employees who reached the top sale (for exaple, i have a max sale of $ 3000, n 3 ppl reached that, ill have to show the code of this 3 ppl and the $3000)
#include "stdafx.h"
#include <iostream>
using namespace std;
void ingresar_legajo ();
void ingresar_ventas (); // prototypes
void comparar_datos ();
struct datos_vendedor
{
int legajo; // code of employee
float total_ventas; //total sales he made
}vendedor;
int main(int argc, char* argv[])
{
ingresar_legajo (); // function to enter the code
comparar_datos (); // function to compare the max sales made
return 0;
}
void ingresar_legajo () // function to enter the code
{
int i;
for (i = 0; vendedor.legajo!=0, i <= 10; i++) //employee.code
{
cout << " Ingrese legajo: "; //enter code
cin >> vendedor.legajo; //read code
while (vendedor.legajo == 0)
ingresar_ventas (); //enter sales
}
}
void ingresar_ventas () // function to enter sales
{
int j;
for (j = 0; j <= 10; j++)
{
cout << "ingrese total ventas: ";
cin >> vendedor.total_ventas; //employee.total_sales (from the struct)
cout << "\n";
}
}
void comparar_datos () // it compares the sales made to find the max
{
int aux = 0;
int max_ventas = 0, vendedor = 0; //max_sales and the seller
float total_ventas;
if (total_ventas > aux) //
{
aux = total_ventas;
max_ventas++;
vendedor++;
}
if (total_ventas == aux)
{
aux = total_ventas;
max_ventas++;
vendedor++;
}
}
when run this, when i enter a 0, it keeps runnin anyway, stops countin the codes of employees, and start askin for ALL the sales made for all the ppl, eventhough i havent entered them.
and if i dont enter a 0, it keep runnin until 11 employees. not 10.
so, this made me doubt about the for statment
for (i = 0; vendedor.legajo!=0, i <= 10; i++)
i dont know if its better to use a while on this... same conditions that in the for, but in a while...
hope i explained that well...
if not ask to explain it better