Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Help : Calculating Ages 2

templenoetemplenoe Member Posts: 7
I need help calculating ages from an array of Students Details.
The ages are read in by YEAR / MONTHS and at the moment i am using

*NOT CODE
For i = 1 to Number of Students
total = total+(CurrentStudent Months)+ (CurrentStudent Years * 12)
CurrentStudent.MoveNext
Next i
Average Age = (total / 12) / Number of Students

However the result of average age gives me someting like 4.5 years
when i want is the result in Years / Months 4 Years and 6 Months

Anyhelp would be greatly accepted

JJ

Comments

  • KDivad LeahcimKDivad Leahcim Member Posts: 3,948
    : I need help calculating ages from an array of Students Details.
    : The ages are read in by YEAR / MONTHS and at the moment i am using
    :
    : *NOT CODE
    : For i = 1 to Number of Students
    : total = total+(CurrentStudent Months)+ (CurrentStudent Years * 12)
    : CurrentStudent.MoveNext
    : Next i
    : Average Age = (total / 12) / Number of Students
    :
    : However the result of average age gives me someting like 4.5 years
    : when i want is the result in Years / Months 4 Years and 6 Months
    :
    : Anyhelp would be greatly accepted
    :
    : JJ
    :

    Simply take the decimal portion and multiply it by 12 to get the number of months.

    Note: If you open your own post, you will see both an edit and a delete link. Please use them instead of making multiple posts. I deleted the other one for you.
  • melissa_may1melissa_may1 Member Posts: 937
    Here's what you need to do to get the months and years separated

    [code]
    AverageAge = total / NumberOfStudents
    AverageYearPortion = Int(AverageAge / 12)
    AverageMonthPortion = Int(AverageAge - (AverageYearPortion * 12))
    AverageDayPortion = (AverageAge - (AverageYearPortion * 12) - AverageMonthPortion) * 30
    [/code]







    [purple]Melissa[/purple]

  • Chris BrownChris Brown USAMember Posts: 4,624 ✭✭

    _____ / http://forcoder.org / free ebooks and video tutorials about | Ruby Swift Delphi Go MATLAB C++ Visual Basic PHP R Perl C JavaScript PL/SQL Objective-C C# Python Scratch Visual Basic .NET Java Assembly SAS Awk F# Logo Scheme Clojure Erlang FoxPro Prolog ML Scala Hack ABAP Dart Alice LabVIEW Apex Julia Bash Lua Transact-SQL D Rust Fortran COBOL Lisp Kotlin Crystal VBScript Ada | _____

Sign In or Register to comment.