// // main.c // T3_Ej12 // // Created by Mari Paz Guerrero Lebrero on 27/1/15. // Copyright (c) 2015 Mari Paz Guerrero Lebrero. All rights reserved. // #include #include #define FILAS 18 #define COLUMNAS 10 int Menu(); float** InicializarVendedores(); float** InsertarVendedor(float **M, int n); float* TotalVendedor(float **M, int n); float IngresosTotales(float **M, int n); int main() { float **vendedores, *t; int f = 1, op, i; vendedores = InicializarVendedores(); op = Menu(); while(op != 4) { switch(op) { case 1:{ if(f >= FILAS) printf("ERROR: No puede introducir mas vendedores\n"); else { vendedores = InsertarVendedor(vendedores, f); f++; } break; } case 2:{ t = TotalVendedor(vendedores, f); for(i = 0; i < (f - 1); i++) printf("Vendedor %d, total ingresos %f\n", i + 1, t[i]); printf("\n"); break; } case 3:{ printf("Los ingresos totales son %f\n", IngresosTotales(vendedores, f)); break; } default:printf("ERROR: Opcion incorrecta\n"); } op = Menu(); } return 0; } int Menu() { int op; printf("---------------------------------------------------\n"); printf("--------------------- MENU ------------------------\n"); printf("---------------------------------------------------\n"); printf("\t1. Insertar vendedor\n"); printf("\t2. Total de ingresos por vendedor\n"); printf("\t3. Ingresos totales\n"); printf("\t4. Salir\n"); printf("ELija una opcion: "); scanf("%d", &op); return op; } float** InicializarVendedores() { float **M; M = (float**)malloc(sizeof(float*)); return M; } float** InsertarVendedor(float **M, int n) { int i; M[n - 1] = (float*)malloc(COLUMNAS*sizeof(float)); for(i = 0; i < COLUMNAS; i++) { printf("Introduzca el ingreso del vendedor %d y el producto %d: ", n, i + 1); scanf("%f", &M[n - 1][i]); } M = (float**)realloc(M, (n+1)*sizeof(float*)); return M; } float* TotalVendedor(float **M, int n) { float *t; int i, j; t = (float*)calloc(n - 1 , sizeof(float)); for(i = 0; i < (n - 1); i++) { for(j = 0; j < COLUMNAS; j++) { t[i] = t[i] + M[i][j]; } } return t; } float IngresosTotales(float **M, int n) { float t = 0; int i, j; for(i = 0; i < (n - 1); i++) { for(j = 0; j < COLUMNAS; j++) { t = t + M[i][j]; } } return t; }