Advertisement
Jvsierra

Prob 2

Aug 1st, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.03 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <string.h>
  4.  
  5. #define LIM 51
  6. #define TFC 2
  7. #define TFV 500
  8. #define TFP 5
  9. #define TFCOL 3
  10.  
  11. int main()
  12. {
  13.     char nomesCli[TFC][LIM], nomesProd[TFP][LIM], cliAux[LIM], prodAux[LIM];
  14.     int matVendas[TFV][TFCOL], posProd, posCli, l, c, cont, tlVendas = 0, estoque[TFP], qntd;
  15.     float preco[TFP], totParc, totVenda;
  16.    
  17.     printf("Cadastro de clientes\n");
  18.    
  19.     for(l = 0; l < TFC; l++)
  20.     {
  21.         printf("Digite o nome do %do cliente:\n", l+1);
  22.         fflush(stdin);
  23.         gets(nomesCli[l]);
  24.     }
  25.    
  26.     printf("Cadastro de produtos\n");
  27.    
  28.     for(l = 0; l < TFP; l++)
  29.     {
  30.         printf("Digite o nome do %do produto:\n", l+1);
  31.         fflush(stdin);
  32.         gets(nomesProd[l]);
  33.        
  34.         printf("Digite o preco:\n");
  35.         scanf("%f", &preco[l]);
  36.        
  37.         printf("Digite a quantidade em estoque:\n");
  38.         scanf("%d", &estoque[l]);
  39.     }
  40.    
  41.     printf("Digite o nome do cliente:\n");
  42.     fflush(stdin);
  43.     gets(cliAux);
  44.    
  45.     while(tlVendas < TFV && strcmp(cliAux, "") != 0)
  46.     {
  47.         posCli = 0;
  48.        
  49.         while(posCli < TFC && strcmp(cliAux, nomesCli[posCli]) != 0)
  50.             posCli++;
  51.            
  52.         if(posCli == TFC)
  53.             printf("Cliente inexistente\n");
  54.         else
  55.         {
  56.             printf("Digite o nome do produto:\n");
  57.             fflush(stdin);
  58.             gets(prodAux);
  59.            
  60.             while(tlVendas < TFV && strcmp(prodAux, "") != 0)
  61.             {
  62.                
  63.                 posProd = 0;
  64.            
  65.                 while(posProd < TFP && strcmp(prodAux, nomesProd[posProd]) != 0)
  66.                     posProd++;
  67.                    
  68.                 if(posProd == TFP)
  69.                     printf("Produto inexistente\n");
  70.                 else
  71.                 {
  72.                     printf("Digite a quantidade:\n");
  73.                     scanf("%d", &qntd);
  74.                    
  75.                     if(estoque[posProd] < qntd)
  76.                         printf("Estoque insuficiente\n");
  77.                     else
  78.                     {
  79.                         matVendas[tlVendas][0] = posCli;
  80.                         matVendas[tlVendas][1] = posProd;
  81.                         matVendas[tlVendas][2] = qntd;
  82.                        
  83.                         estoque[posProd] -= qntd;
  84.                        
  85.                         tlVendas++;
  86.                        
  87.                         printf("Venda efetuada\n");
  88.                     }
  89.                 }
  90.                
  91.                 if(tlVendas < TFV)
  92.                 {
  93.                     printf("Digite o nome do produto:\n");
  94.                     fflush(stdin);
  95.                     gets(prodAux);
  96.                 }
  97.             }
  98.         }
  99.        
  100.         if(tlVendas < TFV)
  101.         {
  102.             printf("Digite o nome do cliente:\n");
  103.             fflush(stdin);
  104.             gets(cliAux);
  105.         }
  106.     }
  107.    
  108.     for(l = 0; l < tlVendas; l+= cont)
  109.     {
  110.         cont = 0;
  111.         totVenda = 0;
  112.        
  113.         printf("Cliente: %d - %s\n", matVendas[l][0], nomesCli[matVendas[l][0]]);
  114.        
  115.         for(c = l; c < tlVendas && matVendas[c][0] == matVendas[l][0]; c++)
  116.         {  
  117.             printf("Produto %d - %s      ", matVendas[c][1], nomesProd[matVendas[c][1]]);
  118.             printf("Preco: %.2f       ", preco[matVendas[c][1]]);
  119.            
  120.             printf("Quantidade: %d        ", matVendas[c][2]);
  121.            
  122.             totParc =  preco[matVendas[c][1]] * matVendas[c][2];
  123.            
  124.             printf("Total: %.2f\n", totParc);
  125.            
  126.             totVenda += totParc;
  127.            
  128.             cont++;
  129.         }
  130.                
  131.         printf("Total da Venda: %.2f\n\n", totVenda);
  132.  
  133.     }
  134.    
  135.     printf("\nExibicao dos produtos em estoque\n\n");
  136.    
  137.     for(l = 0; l < TFP; l++)
  138.     {
  139.         printf("Produto: %d - %s   ", l, nomesProd[l]);
  140.         printf("Preco: %.2f   ", preco[l]);
  141.         printf("Quantidade em estoque: %d\n", estoque[l]);
  142.        
  143.         printf("\n");
  144.     }
  145.    
  146.     getch();
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement