First of all, thank you for your prompt responses.
I have to say that I'm still getting used to this with C ++, so I assume that I made several mistakes now that they are mentioned to me ...
I have fixed the loops as I thought they were appropriate, and I modified the declaration of the variables to design one that took all the values that were placed (that is, no procedure gets to modify it for something else, so we will not have to subtract apples from the thing). With this also the user should be able to decide the number of notes, and therefore the number of elements in the variable.
Still, the program continues to crash, specifically when placing a second rating. What's more: if the number of Notes is 1, the program enters the loop and does not stop asking for grades ...
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
|
#include <iostream>
using namespace std;
int main() {
int Notas = 0;
int promedio = 0;
int calificaciones = 0;
bool reinicio = 1;
while(reinicio == 1){
cout<<"\n";
cout<<"Ingrese numero de notas totales: ";
cin>> Notas;
int recopilacion[Notas];
cout<<"\n";
cout<<"El numero total de notas es: %.2f\n\n", Notas;
for(int i = Notas; i > 0; i--) {
cout<<"Introducir calificacion: ";
cin>>calificaciones;
promedio += calificaciones;
recopilacion[i] += calificaciones;
}
cout<<"\n";
cout<<"El promedio de las calificaciones del alumno es: ";
cout<< promedio/Notas;
cout<<"\n";
cout<<"\n";
cout<<"Las notas superiores a 15 son: \n";
for(int i = 0; i < Notas; i++){
if(recopilacion[i]>15){
cout<<"recopilacion[i] \n";
}
}
cout<<"\n";
cout<<"\n";;
cout<<"¿Desea inicia nuevamente el programa? 1 para si, 0 para no\n";
cin >> reinicio;
}
system ("PAUSE");
return 0;
}
|
Edit: Trying to make the code from scratch I have come up with this one again which seems to be going pretty well. It performs the average, gives freedom of the number of notes, and shows the values greater than 15, but the problem is precisely in this last step, where for some reason some values are shown with numbers like 26688 or similar.
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
|
#include <iostream>
using namespace std;
int main() {
int Notas = 0;
int calificaciones = 0;
int total = 0;
bool reinicio = 1;
while(reinicio==1){
cout<<"Introducir numero de Notas\n";
cin>>Notas;
int promedio[Notas];
for(int i = Notas; i > 0; i--) {
cout<<"Introducir calificacion: ";
cin>>calificaciones;
total += calificaciones;
promedio[i] = calificaciones;
}
cout<<"\n";
cout<<"El promedio de las calificaciones del alumno es: \n";
cout<< total/Notas<<"\n";
cout<<"Las notas superiores a 15 son: \n";
for(int i = 0; i < Notas; i++){
if(promedio[i]>15){
cout<<promedio[i]<<"\n";
}
}
cout<<"\n";;
cout<<"¿Desea inicia nuevamente el programa? 1 para si, 0 para no\n";
cin >> reinicio;
}
system ("PAUSE");
return 0;
}
|