Q:

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

belongs to collection: Ruby Basic Programs

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Ruby Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Ruby program to demonstrate the bitwise left-shift... >>
<< Ruby program to find the largest number among thre...