I have a program that i need to get done that gets the person's name and his grade then prints it in this order "name-grade-gradeletter" so i wrote this code:
#!/bin/bash
while :; do
read -p "Enter the person's name: " name
read -p "Enter the grade of the person: " grade
case $grade in
[50-59]) echo "$name $grade F";;
[60-69]) echo "$name $grade C";;
[70-79]) echo "$name $grade B";;
[80-100]) echo "$name $grade A";;
*) echo "Wrong input"
esac
done
echo "Goodbye"
So when you input the name and the grade, it just skips to the asterisk and outputs "Wrong input". Shouldn't it go through the values since the case is $grade and is using grade that is given by the person ?
Can someone tell me my mistake ?
P.S i tried changing the case to if command to see if it works but it shows me that no such file exists ?:
if [$grade >= 50||$grade < 60]; then
echo "$name $grade F"
elif [$grade >= 60||$grade < 70]; then
echo "$name $grade C"
elif [$grade >= 70||$grade < 80]; then
echo "$name $grade B"
elif [$grade >= 80||$grade <= 100]; then
echo "$name $grade A"
else
echo "Wrong input"
fi
Hmmm - that request looks pretty much like homework.
Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.
Please review the rules, which you agreed to when you registered, if you have not already done so.
More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.
If that request is NOT homework, please give some background and / or context for the request, like the research field the problem comes from, company or business category, or alike.
"Write a shell script program that will input a name and a mark between 0 and 100. The program then displays the name, the mark, and a letter grade for the mark, as per the following grade cut formula."