Lab 6

 

CODE RUNNING SUMMARY SCRIPT

Name Scrip

SUMMARY

This script below asks the user to enter name, course code and grade percentage. After you input all the information that you are asked, it uses the grading scale in the syllabus to display “Hello Name. Your grade for Course code is Grade”. This Script uses an if loop, the first statement is used to establish a range greater than or equal to 93- and less than or equal 100 so that if a uses enter any number from 93 to 100 and also include those two numbers. The rest of the script consist of elif which basically mean that if the if statement is false use the correct statement. The else is used to help to basically cover the rest of the program displaying a message if the user decides to enter an invalid number. The program is then closed with the command fi which used to end the script.

SCRIPT CODE

#!/bin/bash
echo “Enter name”
read name
echo “Enter the Course code”
read coursecode
echo “Enter the Grade Percentage”
read grade
if [ $grade -ge 93 ] && [ $grade -le 100 ]; then
echo ” Hello $name the grade you got in $coursecode is A ”
elif [ $grade -ge 90 ] && [ $grade -le 92.9 ]; then
echo “hello $name the grade you got in $coursecode is A-”
elif [ $grade -ge 87 ] && [ $grade -le 89.9]; then
echo ” Hello $name the grade you got in $coursecode is B+”
elif [ $grade -ge 83 ] && [ $grade -le 86.9 ]; then
echo ” Hello $name the grade you got in $coursecode is B ”
elif [ $grade -ge 80 ] && [ $grade -le 82.9 ]; then
echo ” Hello $name the grade you got in $coursecode B-”
elif [ $grade -ge 77 ] && [ $grade -le 79.9 ]; then
echo ” Hello $name the grade you got in $coursecode is a C+”
elif [ $grade -ge 70 ] && [ $grade -le 76.9 ]; then
echo ” Hello $name the grade you got in $coursecode is C ”
elif [ $grade -ge 60 ] && [ $grade -le 69.9 ]; then
echo ” hello $name the grade you got in $coursecode is D”
else echo “F , you are a failure, you loser”
fi

___________________________________________________________________________________________________________

CODE RUNNING

Fish 56

SUMMARY

This script below asks the user to for an integer n, and displays the sum of the first n numbers. We begin this lonely script by first writing #!/bin/bash which is the name of the interpreter to be used to execute the script and the folder were the file will be placed. We make sum equal to 0 and make a for loop that going to add the variable i which is equal to 1 and add the statement that if i is less or equal n and i+i. we then add do to let the total sum equal to (0+x),(x+x),(2x+x),(3x+x) etc….until it is less than or equal to the input. We then finish the script off by add echo $sum which mean to run the loop and take the end result and that will be your sum.

SCRIPT CODE

#!/bin/bash
echo ” Please enter a positive number ”
read number

sum=0

for((x=1; x <=number ; x++))
do
let sum=$sum+$x
done

echo “sum= “$sum

Leave a Reply

Your email address will not be published. Required fields are marked *