I'm learning C, but a friend of mine asked for help with this code. I have debugged it with C::B and actually it crashes when getting out of the switch and starting to print out the menu again, after selection the first option (1. Polinomio)
I 'watched' the polinomio pointer (float polinomio[n]) and it seems to be working, so i don't know where the segmentation fault is coming from. What do i ignore?
#include <iostream>
using namespace std;
int main() {
int opcion;
do
{
cout << "1. Polinomio \n\n";
cout << "2. Algoritmo de Horner \n\n";
cout << "3. Salir \n\n\n";
cout << "Opcion: ";
cin >> opcion;
cout << "\n\n";
switch(opcion)
{
case 1:
cout << "Opcion polinomio: \n\n";
cout << "Grado de polinomio (n): ";
unsigned n;
cin >> n;
cout << "Introduzca los coeficientes de p(x): \n";
float polinomio[n];
for (unsigned i=0; i<n; i++) {
cout << "a(" << i << ") = ";
cin >> polinomio[i];
cout << "i = " << i << ", polinomio["<<i<<"] = " << polinomio[i] << endl;
}
break;
case 2:
cout << "Opcion Algoritmo de Horner \n\n";
cout << "ENTRADA: \n";
cout << "Orden de la derivada (m>=0): ";
int m;
cin >> m;
cout << "Punto donde evaluar la derivada (z): ";
float z;
cin >> z;
cout << "\n\n\nSALIDA: \n";
cout << "Ultimo cociente (q-n-m-1(x)) = ";
// CODIGO
cout << "\nValor de la derivada (p(m)(z)) = ";
// CODIGO
break;
case 3:
cout << "Bye bye\n";
return 0;
default:
cout << "Opcion incorrecta";
break;
}
} while (1);
return 0;
}