How to create a program to calculate different subjects average

434 views
Skip to first unread message

Bárbara Salinas

unread,
Oct 10, 2015, 10:57:13 AM10/10/15
to MIT App Inventor Forum
Hello, I am not an expert programmer, but I am trying to teach my students how to create a program that calculates the average of n number of subjects.
i.e. Proceso promCali
Escribir "¿Cuántas materias tienes? "
Leer numMaterias
acum=0
Para i<-1 Hasta numMaterias Hacer
Escribir "Escribe el promedio de la materia ",i,":"
Leer valorMat
acum=acum+valorMat
Fin Para
promedio=acum/numMaterias
Escribir "Tu promedio con ",i-1," número de materias es: ",promedio
FinProceso

I already created a design, and I am trying to use the for cycle in AI2, but the difficult part is when we have to ask how many subjects you want to include in the average.  Do I have to create more than one screen?
Could you help me to find a solution? Thanks in advance and have a very nice day :)




Ghica

unread,
Oct 10, 2015, 5:07:28 PM10/10/15
to MIT App Inventor Forum
Try to avoid adding more screens. It is most likely not needed. Could you show your design and the blocks you created? I am sorry but I do not understand you Spanish.
Cheers, Ghica.

SteveJG

unread,
Oct 10, 2015, 5:34:41 PM10/10/15
to mitappinv...@googlegroups.com
These are Forum discussions about how to calculate a grade point average Barbara ... Calculating the average appears to be part of what you want to do ...   https://groups.google.com/forum/#!searchin/mitappinventortest/gpa

One of these apps in the MIT Gallery might also be interesting   


...and here is another ;possible resource, in the MIT Classic Gallery  http://classic-gallery.appinventor.mit.edu/#page%3DApp%26uid%3D805002%26label%3DGPA%20Calculator      it is a zip source file of AI Classics which you might be able to convert to AI2 using the MIT ai to ai2 conversion program


Regards,
Steve



Bárbara Salinas

unread,
Oct 10, 2015, 6:25:44 PM10/10/15
to MIT App Inventor Forum
Steeeeve thank you very much :)

I am going to check them.  Right now I am creating a table layout where I am planning to store the grades for 5 subjects, then I am planning to use a tinyDB to store the information so later I can calculate the average.

But the question is... if the user would like to store more than 5 subjetct, how  am I going to do that?

I am very happy learning how to program, let me tell you that I studied Systems many years ago, but I never learned how to do that.  But now I am planning to continue studying and learning so I can be an excelent Teacher for my students.

Happy inventing Steve, and thanks for all your help :) :) :)

Abraham Getzler

unread,
Oct 10, 2015, 8:37:52 PM10/10/15
to MIT App Inventor Forum
You also have to learn to work with lists in AI2, to break through any fixed number of subjects.

ABG


Scott Ferguson

unread,
Oct 10, 2015, 10:17:36 PM10/10/15
to MIT App Inventor Forum
Hola, Bárbara-

The problem with using App Inventor for such a demonstration is that it is not really a procedural language.
It is rather, event-driven -- responding to sensor input or user input.
But I have attempted to follow your algorithm as closely as I could.
The user would enter a number in the numMaterias TextBox.
Then he would press the Comenzar button.
A number would be entered in the valorMat TextBox.
Then the Siguiente button would be pressed.
These two steps would repeat for the number of grade scores.
When the number of scores entered is numMaterias, the average is displayed.
The user can then press the denuevo button to average another set of grade scores.







---
sf 
NotaMedia.aia

Bárbara Salinas

unread,
Oct 11, 2015, 6:43:23 AM10/11/15
to MIT App Inventor Forum
Wow Scott, your program really help me, not only to understand how to define and use the variables, but also to realize which is the difference between the procedural language and the event-driven program.  Apart from that I can see that we don´t need a tinyDB to store the information about the different grades.

Sorry for bothering you so much, but I just have a question, is there any way to use the "For each" control in this program so I can show my students how to use it in AI2?

I sincerely appreciate that you tryed to understand my spanish program, because I was trying to get screenshots from my blocks but I couldn´t paste the images :) :) :)

Scott Ferguson

unread,
Oct 12, 2015, 12:35:36 AM10/12/15
to MIT App Inventor Forum
You can use foreach if the grades are typed into a textbox separated by commas.

74,93,67,etc.
Then use the list from csv row block to convert that to a list.
The for each block can then iterate through the list to add the numbers together.
---
sf


Reply all
Reply to author
Forward
0 new messages