Good, I don't understand why the program doesn't compile, besides that, I have no idea how much it has to show the grades, it also gives me the average of the grades and what is the highest and lowest grade.
Showing the notes in an orderly way is superfluous, it's not necessary, I just added it for aesthetics, and I don't know if I'm implementing the functions correctly in the code.
Also, if more improvements can be implemented, I would greatly appreciate it.
struct nodo {
int dato;
nodo *siguiente;
}
void insertarLista(Nodo *& int );
void mostarLista(Nodo *);
int main() {
nodo *lista = NULL;
int dato;
menu();
getch();
return 0;
}
void menu() {
int opcion
do {
cout << "MENU: ";
cout << "1. Insertar Nota ";
cout << "2. Mostar Notas ";
cout << "3. Salir ";
cin >> opcion;
switch (opcion) {
case 1:
cout << "Ingrese Las Notas: ";
cin >> dato;
insertarLista(Lista, dato);
cout << "\n";
system("pause");
break;
case 2:
MostarLista(lista);
cout << "\n";
system("pause");
break;
}
system("cls");
}
while (opcion != 3);
}
void insertarLista(Nodo *&lista, int n) {
Nodo *nuevo_nodo = new Nodo();
nuevo_nodo->dato = n;
Nodo *aux1 = lista;
Nodo *aux2;
while ((aux1 != NULL) && (aux1->dato < n)) {
aux2 = aux1;
aux1 = aux1->siguiente;
}
if (lista == aux1) {
lista = nuevo_nodo;
} else {
aux2->siguiente = nuevo_nodo;
}
nuevo_nodo->siguiente = aux1;
}
void mostrarLista(Nodo *lista) {
Nodo *acual = new nodo();
actual = lista;
while (actual != NULL) {
cout << actual->dato << " -> ";
}
}
The code has several problems.
At the end of some instructions are missing
;
. When closing the structureNodo
and in the variableopcion
.Symbol names are inconsistent. On some sites they are in uppercase, on others they are lowercase or even missing a letter.
The function declaration is missing
menu
.A comma is missing to separate the parameters of the function
insertarLista
.There are references to variables out of scope:
In the function
mostrar
a Node is created unnecessarily and the variableactual
never changes. Therefore an infinite loop occurs.May
getch
not be available on all compilers. Better usecin.get()
.If you have the possibility to replace the functions
system
with something better, do it. Since they only work with commands from your operating system.The code could look like this:
I am going to mention the observations that I found in your code. First take into account the order in which you will be structuring your functions. Let's take an example:
When you want to call a function that is below, it will throw an error because the c++ code reads the code from top to bottom , and in this case the first thing that is being read is the function call before the function is defined, so which will not recognize it yet. The solution to this would be that the code first reads the defined function and then calls it:
Or also, you can declare the function above your
int main()
and below what the function will contain, this would give the same result:Now the next observation is that you have a lot of syntax errors:
;
in your code.Regarding the last comment, remember that c++ is
case-sensitive
, for example:Fixing the syntax and remarks in your code, it would look like this:
Output: