Tema: Error en C++
Ver Mensaje Individual
  #2 (permalink)  
Antiguo 05/07/2013, 10:21
amchacon
 
Fecha de Ingreso: julio-2012
Mensajes: 375
Antigüedad: 11 años, 9 meses
Puntos: 28
Respuesta: Error en C++

Pues que tienes un lío de llaves impresionante.

Tabula código tal que así y se verá mejor:

Código C++:
Ver original
  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int i,j,N,opc;
  9.     int tmes[12];
  10.     int MP[N][12];
  11.     int matriz[N][12];
  12.     int ventas[N];
  13.     int mayor, mostrar, pre;
  14.     string meses[12]= {"Ene", "Feb", "Mar", "Abr", "May", "Jun", "Jul", "Ago", "Sep", "Oct", "Nov", "Dic"};
  15.     float pro_mes, acum, d1, d2, d3, total;
  16.     for (i=0; i<12; i++) tmes[i]=0;
  17.     for (i=0; i<N; i++) ventas[i]=0;
  18.  
  19.     do
  20.     {
  21.         cout << "Numero de productos a ingresar: ";
  22.         cin >> N;
  23.         system ("CLS");
  24.     }
  25.     while (N<2);
  26.     string pro[N];
  27.     for (i=0; i<N; i++)
  28.     {
  29.         cout << "Ingrese el nombre del producto ["<<(i+1)<<"]: ";
  30.         cin >> pro[i];
  31.     }//for
  32.     system("cls");
  33.     bool aux = false;
  34.  
  35.     do  //Menu
  36.     {
  37.         system("cls");
  38.         cout << "Menu de opciones" << endl << endl;
  39.         cout << " 0. Salir del sistema" << endl;
  40.         cout << " 1. Ingresar datos por teclado" << endl;
  41.         cout << " 2. Mostrar tabla de inventario y tabla de precios" << endl;
  42.         cout << " 3. Total de ventas de cada producto" << endl;
  43.         cout << " 4. Total de ventas por mes" << endl;
  44.         cout << " 5. Producto mas vendido por mes" << endl;
  45.         cout << " 6. Nombre, mes y cantidad de producto mas vendido" << endl;
  46.         cout << " 7. Porcentaje de producto mas vendido por cada mes" << endl;
  47.         cout << " 8. Porcentaje vendido de cada producto" << endl;
  48.         cout << " 9. Ganancias totales y deducciones" << endl;
  49.         cout << "Escoja una opcion:[ ]\b\b\b" ;
  50.         cin >> opc;
  51.         system("cls");
  52.  
  53.  
  54.         switch(opc)
  55.         {
  56.         case 1:
  57.             system ("cls");
  58.             do
  59.             {
  60.                 cout << "Ingrese costo del primer producto: ";
  61.                 cin >> pre;
  62.                 system("cls");
  63.             }
  64.             while(pre <= 0);
  65.             for(i=0; i<N; i++)
  66.                 for(j=0; j<12; j++)
  67.                 {
  68.                     do
  69.                     {
  70.                         cout << "Ingrese la venta del mes "<<meses[j]<<" del producto "<<pro[i]<<" = ";
  71.                         cin >> matriz[i][j];
  72.                         system ("cls");
  73.                     }
  74.                     while(matriz[i][j]<0);
  75.                 }//for
  76.             aux = true;
  77.  
  78.             break;
  79.         case 2:
  80.             system("cls");
  81.             if (aux)
  82.  
  83.             {
  84.                 cout << "1. Tabla de precios" << endl;
  85.                 cout << "2. Tabla de productos" << endl << endl;
  86.                 cout << "Seleccione su opcion[ ]\b\b\b";
  87.                 cin >> mostrar;
  88.                 acum = pre;
  89.                 if(mostrar == 1)
  90.                 {
  91.                     system("cls");
  92.                     for (i=0; i<N; i++)
  93.                     {
  94.                         cout << "\t" << pro[i];
  95.                     }//for
  96.                     cout << endl;
  97.                     for(i=0; i<N; i++)
  98.                     {
  99.                         cout << "\t" << acum;
  100.                         acum = acum + 15;
  101.                     }//for
  102.                     cout << endl;
  103.                 }//if
  104.  
  105.                 if(mostrar == 2)
  106.                 {
  107.                     for(j=0; j<6; j++)
  108.                     {
  109.                         cout << "\t" << meses[j];
  110.                     }//for
  111.                     cout << endl;
  112.                     for (i=0; i<N; i++)
  113.                     {
  114.                         cout << pro[i];
  115.                         for (j=0; j<6; j++)
  116.                         {
  117.                             cout << "\t" << matriz[i][j];
  118.                         }//for
  119.                         cout << endl;
  120.                     }//for
  121.                     system("pause");
  122.                     system ("cls");
  123.                     for (j=6; j<12; j++)
  124.                     {
  125.                         cout << "\t" << meses[j];
  126.                     }//for
  127.                     cout << endl;
  128.                     for (i=0; i<N; i++)
  129.                     {
  130.                         cout << pro[i];
  131.                         for (j=6; j<12; j++)
  132.                         {
  133.                             cout << "\t" << matriz[i][j];
  134.                         }//for
  135.                         cout << endl;
  136.                     }//for
  137.                 }//if
  138.             }//if
  139.             else
  140.                 cout << "Debe ingresar datos."<<endl<<endl;
  141.             break;
  142.         case 3:
  143.             system ("CLS");
  144.             if (aux)
  145.             {
  146.                 for(i=0; i<N; i++)
  147.                     for(j=0; j<12; j++)
  148.                     {
  149.                         ventas[i] = ventas[i] + matriz[i][j];
  150.                     }//for
  151.                 for(i=0; i<N; i++)
  152.                     cout << "La venta del producto "<<pro[i]<<" es: " << ventas[i] << endl;
  153.             }//if
  154.             else
  155.                 cout << "Debe ingresar datos." <<endl << endl;
  156.             break;
  157.         case 4:
  158.             system("cls");
  159.             if(aux)
  160.             {
  161.                 for (i=0; i<12; i++)
  162.                     for (j=0; j<N; j++)
  163.                     {
  164.                         tmes[i]= tmes[i] + matriz[j][i];
  165.                     }//for
  166.                 for(i=0; i<12; i++)
  167.                     cout << "La venta del mes "<<meses[i]<<" es: " << tmes[i] <<endl;
  168.             }//if
  169.  
  170.             else
  171.                 cout << "Error! Debe ingresar datos." << endl << endl;
  172.             break;
  173.         case 5:
  174.             break;
  175.         case 6:
  176.             break;
  177.         case 7:
  178.             system("cls");
  179.             {
  180.                 for (j=0; j<12; j++)
  181.                 {
  182.                     for (i=0; i<N; i++)
  183.                     {
  184.                         tmes[j] = tmes[j] + matriz[i][j];
  185.                     }//for
  186.  
  187.                     acum = acum + tmes[j];
  188.                 }//for
  189.  
  190.                 for (j=0; j<12; j++)
  191.  
  192.                 {
  193.                     pro_mes = ((tmes[j]/acum)*100);
  194.                     cout << "El porcentaje en el mes "<<meses[j]<<" es "<<pro_mes<<"%"<< endl << endl;
  195.                     system ("pause");
  196.                     system ("cls");
  197.                 }//for
  198.                 break;
  199.             case 8:
  200.             {
  201.                 acum = 0;
  202.                 for (i=0; i<N; i++)
  203.                 {
  204.                     for (j=0; j<12; j++)
  205.                     {
  206.                         ventas[i] = ventas[i] + matriz[i][j];
  207.                     }//for
  208.                     acum = acum + ventas[i];
  209.                 }//for
  210.                 for (i=0; i<N; i++)
  211.                 {
  212.                     pro_mes = ((ventas[i]/acum)*100);
  213.  
  214.                     cout << "El porcentaje del producto "<<pro[i]<<" es "<<pro_mes<<"%"<< endl <<endl;
  215.                 }//for
  216.  
  217.                 break;
  218.                 case 9:
  219.                 {
  220.                     for (j=0; j<12; j++)
  221.                     {
  222.                         total = 0;
  223.                         for (i=0; i<N; i++)
  224.                         {
  225.                             pre = pre + 15;
  226.                             total = total + (pre*matriz[i][j]);
  227.                         }//for
  228.                         system("cls");
  229.  
  230.                         d1 = (total*0.15);
  231.                         d2 = (total*0.16);
  232.                         d3 = (total*0.215);
  233.                         cout << "Las ganancias en el mes "<<meses[j]<<" son: "<<(total-d1-d2-d3)<<endl;
  234.                         cout << "Las deducciones por servicio en el mes "<<meses[j]<<" son: "<<d1<<endl;
  235.                         cout << "Las deducciones por impuestos en el mes "<<meses[j]<<" son: "<<d2<<endl;
  236.                         cout << "Las deducciones por pagos a los empleados en el mes "<<meses[j]<<" son: "<<d3<<endl;
  237.                         system ("PAUSE");
  238.                     }//for
  239.                     break;
  240.                 }//switch
  241.                 system ("PAUSE");
  242.             }
  243.             while (opc !=0);
  244.         }

Usa funciones, comenta las llaves... Tienes que ganar en claridad de código ;)