Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
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.
2. Relevant commands, code, scripts, algorithms:
case/read/echo/if
3. The attempts at a solution (include all code and scripts):
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:
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 ?:
4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Your logic is correct, you syntax/punctuation is faulty.
Using the case statement:
Somehow I think that the 50-59 mark should be "D" and less than 50 an "F".
The error is in this part "[50-59]". Do the comparison one character at a time rather than a numeric test.
Using if statements:
Spaces in the test statement are important.
What operators are used for numeric tests, and which for alphabetic?
You are using a loop that is never exited, no matter what the input.
Also, there is a difference between a string comparison and a numerical comparison.
A case statement can only match patterns. Like @jgt mentioned, in that syntax a pattern like [50-59] will match a single character, in this case when it is 5, 0-5 or 9.
The [ ... ] syntax does not allows for the use of || within the brackets.
You would need to use
For numerical comparisons keywords like -eq, -lt, -le and such are used (see man test)
--
Note: Be careful with spaces < = is not the same as <=
Last edited by Scrutinizer; 04-16-2018 at 12:03 AM..
This User Gave Thanks to Scrutinizer For This Post:
hello everyone!:)
I have an exercise which I think is difficult for beginner like me. Here is the exercise
Create a shell script, which takes a directory as command line argument.
Script displays ten first lines from every text file in that directory. After
displaying the lines from the... (1 Reply)
you are to write a program which will read in a tax rate (as a percentage) and the prices of 5 items. the program is to calculate the total price, before tax, of the items and then the tax payable on those items, and then the total amount due. the tax payable is computed by appliying the tax rate... (1 Reply)
Hi, 'm trying to do an exercicise, and one part is:
ls -l $1 | awk '
BEGIN {
max = $5;
}
{
if ($5 > max){
max = $5;
}
}
END {
print "Tamanio mayor fichero = " max; }'
# Imprimimos ahora el menor tamaņo de fichero
ls -l $1 | awk '... (4 Replies)
How do I write a shell script file to read 5 student names (First and Last name) and their grades using a While Loop? Find the Average, Maximum, and Minimum of grades using the same While Loop. Prompt the user using tput to enter the information (first name, last name, grade). Save the data in a... (1 Reply)
Hello guys.
Well, on this exercise i need the average "chargeAmount" per hour (for each hour).
with this code :
cat getusagesummarywrongmatch | grep -iv MOU2GRTObject | cut -d'|' -f4,14 | grep -i chargeamount | cut -d' ' -f2
http://img227.imageshack.us/img227/5889/65969235do0.jpg
i got... (2 Replies)
Hello guys..
well, im kinda newbie with unix because i started to learn it like 2 weeks ago.
then i started to make some exercises, but i got stucked on this one :
so, i need to know how many different 'names' has the 5th field and how many times each name appears.
i was trying with a... (6 Replies)