Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 04-26-2005, 07:57 PM   #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
Diggler is offline   Reply With Quote
Old 04-26-2005, 09:55 PM   #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.
mattg2k4 is offline   Reply With Quote
Old 04-27-2005, 06:22 AM   #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
Diggler is offline   Reply With Quote
Old 04-27-2005, 06:58 AM   #4
Member (7 bit)
 
shaticus's Avatar
 
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
shaticus is offline   Reply With Quote
Old 04-28-2005, 09:48 AM   #5
Member (6 bit)
 
Join Date: Jan 2004
Posts: 37
Quote:
Originally Posted by shaticus
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
u made that look too east lol thx I was totally wrong on that approach
Diggler is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:21 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2