|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (6 bit)
Join Date: Jan 2004
Posts: 37
|
Unix
if you know how to program in UNIX I NEED HEEEELLLLPPPPPP! here are some of the programs I wrote that arent working. Can you guide my in what I did wrong
1. Create a program that will ask the user if they want to add, subtract, multiply or divide two user inputted numbers. Then give the response as follows: The sum of number1 and number 2 is: Answer The difference of number1 and number2 is: Answer The product of number1 and number2 is: Answer The quotient of Number1 and Number2 is: Answer #!/bin/sh echo “Do you want to add, subtract, multiply, or divide” read choice if [ $choice = add] then echo “Enter a Number” read num1 echo “enter another number” read num2 let x=$num1 + $num2 echo $x elif [ $choice = subtract ] then echo “Enter a Number” read num1 echo “enter another number” read num2 let x=$num1 - $num2 echo $x elif [ $choice = multiply ] then echo “Enter a Number” read num1 echo “enter another number” read num2 let x=$num1 \* $num2 echo $x elif [ $choice = divide ] then echo “Enter a Number” read num1 echo “enter another number” read num2 elif [$num2 = 0] then echo “division by zero error will occur.” Echo “choose another number” Read num2 let x=$num1 \ $num2 echo $x else [$choice = quite] then echo “you are done” fi on this one this is as far as I got now im stumped 4. Write a program that will allow a user to input as many numbers as the user wants (use 999 as the choice that ends the user input). The program will then respond: Highest Number: Answer Lowest Number: Answer Sum of the numbers: Answer Average of the numbers: Answer #!/bin/sh until [ count=999 ] do echo "Enter a number" read num1 echo "Enter another number" read num2 let count=count + 1 last but not least 6. Write a program that will allow a user to type in a number, then the number will either count up to the number provided by the user or count down from that number. In addition, create a menu that will let the user choose which counter they wish to use. In both cases that counter will either count down to 0, or start counting from 0 echo “choose to count up or down” read choice echo “Please enter a number” read num if [ choice = up ] then count=0 until [ $count = $num ] do echo $count let count=counter + 1 echo $count done else count=$num until [ $count = 0 ] do echo $count let count=count – 1 done thx for n e help |
|
|
|
|
|
#2 |
|
Member (10 bit)
Join Date: Jul 2002
Location: University of California, Santa Barbara
Posts: 800
|
I'm assuming this is a shell script of some sort? I don't know much about those, but even I could try and help if you told us what problems you are having with these homework problems.
|
|
|
|
|
|
#3 |
|
Member (6 bit)
Join Date: Jan 2004
Posts: 37
|
they dont show any results, it is a shell sript. i cant tell whether or not there is a problem and if there is it usually says line"##" error ## meaning number 1 or 2 or 39
|
|
|
|
|
|
#4 |
|
Member (7 bit)
Join Date: May 2004
Posts: 103
|
I havent done much with shell scripting, but for number 4 you want to do something like this
#!/bin/sh echo "Enter a number" read num1 //sets all variable to first number - since this is the first number it will be the highest and lowest so far. highest = num1 total = num1 smallest = num1 until [ count=999 ] do echo "Enter a number" read num1 //if number entered is greater than the highest so far set that number to highest. if[num1 > highest] highest = num1 //if number entered is less than the highest so far set that number to lowest. if[num1 < lowest] lowest = num1 //keeps track of all numbers so far total = total + num1 let count=count + 1 //outside of loop output your text and answer Highest Number: highest Lowest Number: lowest Sum of the numbers: total Average of the numbers: total / count |
|
|
|
|
|
#5 | |
|
Member (6 bit)
Join Date: Jan 2004
Posts: 37
|
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|