[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Storing User Input in Tables/Arrays
- From: Sean Conner <sean@...>
- Date: Fri, 5 May 2017 18:38:08 -0400
It was thus said that the Great Jorge Eduardo de Araújo Oliveira once stated:
> Hi, guys!
>
> I know it sounds noob, but it's noob !! LOL!
> I'm studing Lua Programming for a few weeks...
>
> The question is:
> How do I store user input in a table/array?
>
> For example, information from a school report card:
>
> Name Grade_1 Grade_2 Average_Grade
>
> John 7.0 8.0 7.5
>
> I'm worried about this.
> Thanks a lot for the help!
I would arrange for the data to be stored as:
data =
{
{ name = "John" , grades = { 7.0 , 8.0 } } ,
{ name = "Sean" , grades = { 7.1 , 7.9 , 6.9 , 8.1 } } ,
{ name = "Sion" , grades = { 6.9 , 8.1 , 8.0 } } ,
{ name = "Jean" , grades = { 7.0 , 8.2 , 7.5 } } ,
}
I would not include the average, but make a function to calculate it from
a list of grades.
-spc (Using an array for the grades is nice because it can be expanded to
include more than just two grades)