In this program we are going to calculate the student results using functions with parameters
func tenthResults(stuName: String, telugu: UInt8, hindi: UInt8, english: UInt8, maths: UInt8, science: UInt8, social: UInt8)
{
//Creating and storing the constants
let passMarksTenth:UInt8 = 35
let maxTotalTenth:UInt16 = 600
print("\(stuName) Tenth Results")
print("::::::::::::::::::::::::")
//Calculating the total marks
let totalMarks:UInt16 = UInt16(telugu) + UInt16(hindi) + UInt16(english) + UInt16(maths) + UInt16(science) + UInt16(social)
//Calculating the percentage of marks
let tenthPercentage:Float = (Float(totalMarks)*100)/Float(maxTotalTenth)
//if condition is used the check the subject wise result
if telugu >= passMarksTenth
{
print("\(stuName) ==> Telugu Marks ==> \(telugu) --- Passed")
}else
{
print("\(stuName) ==> Telugu Marks ==> \(telugu) --- Failed")
}
if hindi >= passMarksTenth
{
print("\(stuName) ==> Hindi Marks ==> \(hindi) --- Passed")
}else
{
print("\(stuName) ==> Hindi Marks ==> \(hindi) --- Failed")
}
if english >= passMarksTenth
{
print("\(stuName) ==> English Marks ==> \(english) --- Passed")
}else
{
print("\(stuName) ==> English Marks ==> \(english) --- Failed")
}
if maths >= passMarksTenth
{
print("\(stuName) ==> Maths Marks ==> \(maths) --- Passed")
}else
{
print("\(stuName) ==> Maths Marks ==> \(maths) --- Failed")
}
if science >= passMarksTenth
{
print("\(stuName) ==> Science Marks ==> \(science) --- Passed")
}else
{
print("\(stuName) ==> Science Marks ==> \(science) --- Failed")
}
if social >= passMarksTenth
{
print("\(stuName) ==> Social Marks ==> \(social) --- Passed")
}else
{
print("\(stuName) ==> Social Marks ==> \(social) --- Failed")
}
//if conditon to check the overall result of student
if (telugu >= passMarksTenth && hindi >= passMarksTenth && english >= passMarksTenth && maths >= passMarksTenth && science >= passMarksTenth && social >= passMarksTenth)
{
print("Congratulations! \(stuName) you have paseed in the examination")
print("Percentage obtained by you is: \(percentage)")
percentage = tenthPercentage
grades()
}else
{
print("Sorry! \(stuName) you have failed in the examination")
}
print("\(stuName) total marks is: \(totalMarks)")
}
No comments:
Post a Comment