Dev - C++ - El programa ha dejado de funcionar

 
Vista:
sin imagen de perfil

El programa ha dejado de funcionar

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


Tengo este código el cual devc++ lo compila sin problemas pero al correr deja de funcionar,gracias de antemano espero su ayuda,me urge este programa.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

El programa ha dejado de funcionar

Publicado por Alexander (2 intervenciones) el 24/10/2017 04:02:29
Lo que pasa es que quieres crear arreglos con valores variable lo cual no se puede porque no puedes modificar su tamaño en ejecución del programa, para eso deberías usar estructuras dinámicas como las listas las cuales su tamaño crece o disminuye, bueno arregle el problema con tamaños constantes abajo te pongo el código corregido:

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

espero que te ayude que te valla bien.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar