Sponsored Content
Full Discussion: Question about function
Top Forums Shell Programming and Scripting Question about function Post 31413 by Perderabo on Thursday 7th of November 2002 11:01:51 AM
Old 11-07-2002
I corrected some of your errors and it at least will run now...
Code:
#!/bin/sh


echo "Welcome To My Phone Book.\n\n"
sleep 2
clear


function main
{
	while : ; do
		echo "1) Add Phone Number\n2) Add Address\n3) Make a new Phone Book.\n4) Exit\n\n"
		echo "Enter: "
		read choice
		
		case $choice in
			1) select1;;
			2) select2;;
			3) select3;;
			4) close;;
		esac
	done
}


function select1
{
    echo "Please Enter the Name: "
    read Name
    echo "Enter the Phone Number: "
    read Number
    echo "Adding To Phone Book..\n"
    sleep 1
    
       	echo "Added Information.\n"
    	echo "==============================================\n\n" >> phone1.log
    	echo "Name: $Name \n" >>phone1.log
    	echo "Phone Number: $Number\n" >> phone1.log
    	echo "==============================================\n\n" >> phone1.log
    	sleep 2
    	return
}

function select2
{
	echo"Please Enter the Name: "
    	read Name2 
    	echo "Enter the House Number: "
    	read HouseNumber 
    	echo "Enter the Phone Number: "
    	read PhoneNumber2 
    	echo "Enter the Town/City: "
    	read TownCity 
    	
    		echo "+=========================================+\n" >> phone1.log
    		echo "Name: $Name2 \n" >> phone1.log
    		echo "House Number: $HouseNumber \n" >> phone1.log
    		echo "Phone Number: $PhoneNumber2 \n" >> phone1.log
    		echo "Town/City: $TownCity \n\n" >> phone1.log
    		echo "+=========================================+\n\n" >> phone1.log
    		
    	
    	echo "Adding Information..\n"
    	sleep 1
    	echo "Information Added.\n"
    	sleep 1
    	return
}

function select3
{
	echo"You only need to Make this once..\n"
    	echo "" >> phone1.log
	return
}

function close
{
	echo "Exiting..\n"
    	sleep 1
    	exit
}

# we can invoke a function only after we defined it.
main

 

10 More Discussions You Might Find Interesting

1. Programming

sco unix 5.0.5 call sytem() function question!please help me!

i want to know the return value of calling system function in the sco unix 5.0.5.what is the meaning of the return value? ............ int ret; char cmd; strcpy(cmd,"compress -F -c file >file.Z"); ret = system(cmd); ............. i want to know how to judge whether the file's compress is... (4 Replies)
Discussion started by: hit
4 Replies

2. UNIX for Dummies Questions & Answers

Date function question

hi guys! just want to ask if you could help me with the sript i'm working on. i need to automatically generate a summarized report everyday for all transactions the day before and ftp it to another machine. my only problem is that i need to name the file as the date yesterday. for example if i... (12 Replies)
Discussion started by: crpalermo
12 Replies

3. Shell Programming and Scripting

Question for calling oracle function from perl

Dear Sir/Madam, I use the following way to call the oracle stored procedure in a perl script, but I do not know how to call a oracle function by the following way ? # ARGV is the oracle stored procedure name with parameters $str = "sqlplus -s <<-eof \n" . "$db_login... (0 Replies)
Discussion started by: ili
0 Replies

4. Programming

Question about the system() function in C

Hello all ! Could someone throw some light on whether there's a limit to the number of characters contained in the command string that is passed to the system() call in C. Is it OS dependent? If yes, what are the limits for each? Thanks. (4 Replies)
Discussion started by: vsanjit
4 Replies

5. Shell Programming and Scripting

A question about the PID of a background function

Dear all, I'm writing a KornShell script that calls inside it a function in background mode #!/bin/ksh function myfunction { . . .} myfunction |& . . . How can I capture the PID of the function myfunction that runs in background? Thanks in advance :) (2 Replies)
Discussion started by: dariyoosh
2 Replies

6. Shell Programming and Scripting

Question about Function calls

Hello everyone, here's my problem: I want to create two shell scripts. one of them should includes some functions, the other one just the function calls. Is this possible? Can i call a function which is placed in a scriptfile eg functions.sh out of another script eg call.sh? :confused: And if... (2 Replies)
Discussion started by: Sebi0815
2 Replies

7. Programming

question about Function pointers

Hello forum memebers As iam new to C++ programming i am little bit confuse to understand the function pointers. Please help me to understand the function pointers with examples are suggest me good site for this,Its better if it have picturial representation ie any PPTS available in Google.... (2 Replies)
Discussion started by: rajkumar_g
2 Replies

8. Programming

question about function object

I have a code as following: #include <iostream> #include <algorithm> #include <list> using namespace std; //the class Nth is a predicates class Nth{ private: int nth; int count; public: Nth(int n):nth(n),count(0){} bool operator()(int){ ... (2 Replies)
Discussion started by: homeboy
2 Replies

9. UNIX for Dummies Questions & Answers

[Solved] Perl Question - split function with csv file

Hi all, I have a csv file that appears as follows: ,2013/03/26,2012/12/26,4,1,"2017/09/26,5.75%","2017/09/26,1,2018/09/26,1,2019/09/26,1,2020/09/26,1,2021/09/26,1",,,2012/12/26,now when i use the split function like this: my @f = split/,/; the split function will split the data that is... (2 Replies)
Discussion started by: WongSifu
2 Replies

10. Shell Programming and Scripting

Question about sorting -- how to pass an array to a function

Hi, guys I just wanted to sort the elements of an array ascendingly. I know the following code does work well: array=(13 435 8 23 100) for i in {0..4} do j=$((i+1)) while ] do if } -le ${array} ]] then : else min=${array} ${array}=${array} ${array}=$min fi... (5 Replies)
Discussion started by: franksunnn
5 Replies
ROUND(3)								 1								  ROUND(3)

round - Rounds a float

SYNOPSIS
float round (float $val, [int $precision], [int $mode = PHP_ROUND_HALF_UP]) DESCRIPTION
Returns the rounded value of $val to specified $precision (number of digits after the decimal point). $precision can also be negative or zero (default). Note PHP doesn't handle strings like "12,300.2" correctly by default. See converting from strings. PARAMETERS
o $val - The value to round o $precision - The optional number of decimal digits to round to. o $mode - Use one of the following constants to specify the mode in which rounding occurs. +--------------------+---------------------------------------------------+ | Constant | | | | | | | Description | | | | +--------------------+---------------------------------------------------+ | | | | PHP_ROUND_HALF_UP | | | | | | | Round $val up to $precision decimal places away | | | from zero, when it is half way there. Making 1.5 | | | into 2 and -1.5 into -2. | | | | | | | |PHP_ROUND_HALF_DOWN | | | | | | | Round $val down to $precision decimal places | | | towards zero, when it is half way there. Making | | | 1.5 into 1 and -1.5 into -1. | | | | | | | |PHP_ROUND_HALF_EVEN | | | | | | | Round $val to $precision decimal places towards | | | the next even value. | | | | | | | |PHP_ROUND_HALF_ODD | | | | | | | Round $val to $precision decimal places towards | | | the next odd value. | | | | +--------------------+---------------------------------------------------+ RETURN VALUES
The rounded value EXAMPLES
Example #1 round(3) examples <?php echo round(3.4); // 3 echo round(3.5); // 4 echo round(3.6); // 4 echo round(3.6, 0); // 4 echo round(1.95583, 2); // 1.96 echo round(1241757, -3); // 1242000 echo round(5.045, 2); // 5.05 echo round(5.055, 2); // 5.06 ?> Example #2 $mode examples <?php echo round(9.5, 0, PHP_ROUND_HALF_UP); // 10 echo round(9.5, 0, PHP_ROUND_HALF_DOWN); // 9 echo round(9.5, 0, PHP_ROUND_HALF_EVEN); // 10 echo round(9.5, 0, PHP_ROUND_HALF_ODD); // 9 echo round(8.5, 0, PHP_ROUND_HALF_UP); // 9 echo round(8.5, 0, PHP_ROUND_HALF_DOWN); // 8 echo round(8.5, 0, PHP_ROUND_HALF_EVEN); // 8 echo round(8.5, 0, PHP_ROUND_HALF_ODD); // 9 ?> Example #3 $mode with precision examples <?php /* Using PHP_ROUND_HALF_UP with 1 decimal digit precision */ echo round( 1.55, 1, PHP_ROUND_HALF_UP); // 1.6 echo round( 1.54, 1, PHP_ROUND_HALF_UP); // 1.5 echo round(-1.55, 1, PHP_ROUND_HALF_UP); // -1.6 echo round(-1.54, 1, PHP_ROUND_HALF_UP); // -1.5 /* Using PHP_ROUND_HALF_DOWN with 1 decimal digit precision */ echo round( 1.55, 1, PHP_ROUND_HALF_DOWN); // 1.5 echo round( 1.54, 1, PHP_ROUND_HALF_DOWN); // 1.5 echo round(-1.55, 1, PHP_ROUND_HALF_DOWN); // -1.5 echo round(-1.54, 1, PHP_ROUND_HALF_DOWN); // -1.5 /* Using PHP_ROUND_HALF_EVEN with 1 decimal digit precision */ echo round( 1.55, 1, PHP_ROUND_HALF_EVEN); // 1.6 echo round( 1.54, 1, PHP_ROUND_HALF_EVEN); // 1.5 echo round(-1.55, 1, PHP_ROUND_HALF_EVEN); // -1.6 echo round(-1.54, 1, PHP_ROUND_HALF_EVEN); // -1.5 /* Using PHP_ROUND_HALF_ODD with 1 decimal digit precision */ echo round( 1.55, 1, PHP_ROUND_HALF_ODD); // 1.5 echo round( 1.54, 1, PHP_ROUND_HALF_ODD); // 1.5 echo round(-1.55, 1, PHP_ROUND_HALF_ODD); // -1.5 echo round(-1.54, 1, PHP_ROUND_HALF_ODD); // -1.5 ?> CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.3.0 | | | | | | | The $mode parameter was introduced. | | | | | 5.2.7 | | | | | | | The inner workings of round(3) was changed to | | | conform to the C99 standard. | | | | +--------+---------------------------------------------------+ SEE ALSO
ceil(3), floor(3), number_format(3). PHP Documentation Group ROUND(3)
All times are GMT -4. The time now is 08:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy