Foros del Web » Programación para mayores de 30 ;) » C/C++ »

Error en C++

Estas en el tema de Error en C++ en el foro de C/C++ en Foros del Web. Estoy haciendo un programa sobre una venta, por acá les dejo el código y el error cuando compilo: @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código C++: Ver original #include ...
  #1 (permalink)  
Antiguo 05/07/2013, 10:00
 
Fecha de Ingreso: julio-2013
Mensajes: 1
Antigüedad: 10 años, 9 meses
Puntos: 0
Error en C++

Estoy haciendo un programa sobre una venta, por acá les dejo el código y el error cuando compilo:

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




Estos son los errores:

Código:
In fuction 'int main()'
expected '}' at end of input
expected '}' at end of input
expected 'while' at end of input
expected '(' at end of input
expected primary-expression at end of input
expected ')' at end of input
expected ';' at end of input
expected '}' at end of input
alguien????

Última edición por razpeitia; 05/07/2013 a las 11:01
  #2 (permalink)  
Antiguo 05/07/2013, 10:21
 
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 ;)

Etiquetas: int, programa, string
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 21:43.