Ruby program to find the division of students based on percentage using ternary operator

Ruby Example: Write a program to find the division of students based on percentage using ternary operator.
Submitted by Nidhi, on December 01, 2021

Problem Solution:

In this program, we will read the percentage of the student from the user. Then we will find the division of students.

Program/Source Code:

The source code to find the division of students based on percentage using the ternary operator is given below. The given program is compiled and executed successfully.

# Ruby program to find the division of students 
# based on percentage using ternary operator

print "Enter percentage: ";
per = gets.chomp.to_f;  

msg=per>=60 ? "FIRST" : per>=45 ? "SECOND" : per>=33 ? "THIRD" : "FAILED";

print "Division is: ",msg;

Output:

Enter percentage: 72.4
Division is: FIRST

Explanation:

In the above program, we read the percentage of the student from the user and found the division of students, and printed the appropriate message.

Ruby Basic Programs »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.