Sponsored Content
Homework and Emergencies Homework & Coursework Questions Creating a calculator with condition Post 303007723 by mugiboya on Monday 20th of November 2017 04:50:40 PM
Old 11-20-2017
Made it work! Thanks!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

calculator program..

Hey can anyone tell me the korn script code to implement an interactive integer calculator using the shell's built in arithemetic expression evaluation (2 Replies)
Discussion started by: sahithi_khushi
2 Replies

2. Shell Programming and Scripting

Calculator

I am pretty new to the Unix word, and have created a working calculator script. I have one problem. It doesn't use any decimals, it rounds off to the nearest whole number. 1 #!/bin/ksh 2 while true; do 3 echo -n "Enter the first integer: "; read IN1 4 test... (2 Replies)
Discussion started by: ironhead3fan
2 Replies

3. UNIX for Dummies Questions & Answers

calculator

hi, im new to the unix system and scripting and was wondering if anyone could help me with this problem iv been havin... i want the system to: 1. ask me for a number 2. ask me for a command to use on that number (* + - /) 3. ask me for another number 4. then ask me for another command, if the... (2 Replies)
Discussion started by: jdougy
2 Replies

4. Shell Programming and Scripting

redirecting output and creating condition for while loop.

I have 2 questions. 1) Is there a means of directing output to a file (">") while making it still output to the console? I have a script that calls another lengthy script. 2) I can direct the output of the lengthy script and grep it for the words "good" or "bad" to know if I need the run... (2 Replies)
Discussion started by: mrwatkin
2 Replies

5. Shell Programming and Scripting

Help with calculator code

Hi Guys, I found this code in net.. it is working fine.. But can anybody explain me the sed statement used in the code.. echo "Enter the expression:\c" read express eval echo "$express"|sed 's/^/'$precision' \ /'|bc -l|\ sed -n '1,${ /syntax/!{ } ... (2 Replies)
Discussion started by: mac4rfree
2 Replies

6. Shell Programming and Scripting

redirect stdout echo command in condition A run in condition B

hi, I have some problems in my simple script about the redirect echo stdout command inside a condition. Why is the echo command inside the elif still execute in the else command Here are my simple script After check on the two diff output the echo stdout redirect is present in two diff... (3 Replies)
Discussion started by: jao_madn
3 Replies

7. Homework & Coursework Questions

Simple Calculator

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: Script a simple calculator. In the command line enter the script file /home/etc/mycalc or /home/etc/mycalc 1 +... (6 Replies)
Discussion started by: herb bertz
6 Replies

8. Shell Programming and Scripting

If condition return 0 even when it fails to satisfy te condition

HI My doubt may be basic one but I need to get it clarified.. When i use "if" condition that checks for many AND, OR logical conditions like if ]; then return 0 fi Even the if condition fails it returns as zero.. Any clue.. But if i add else condition like if ]; ... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

9. Shell Programming and Scripting

Creating a condition on a bash script

I wrote a code to find codons in a DNA string. The only problem I have is how do I make the code only work for a file with DNA. This means the file only has the characters a,c,g,t and no white space characters. (3 Replies)
Discussion started by: germany1517
3 Replies

10. UNIX for Beginners Questions & Answers

Creating a calculator with condition

So have I got this : #!/bin/bash clear echo "Enter the first number:" read n1 echo "Choose an operation:" echo "1. add" echo "2. subtract" echo "3. multiply" echo "4. divide" read opr echo "Enter the second number:" read n2 (1 Reply)
Discussion started by: mugiboya
1 Replies
STREAM_NOTIFICATION_CALLBACK(3) 					 1					   STREAM_NOTIFICATION_CALLBACK(3)

stream_notification_callback - A callback function for the notificationcontext parameter

SYNOPSIS
void stream_notification_callback (int $notification_code, int $severity, string $message, int $message_code, int $bytes_transferred, int $bytes_max) DESCRIPTION
A callable function, used by the notification context parameter, called during an event. Note This is not a real function, only a prototype of how the function should be. PARAMETERS
o $notification_code - One of the STREAM_NOTIFY_* notification constants. o $severity - One of the STREAM_NOTIFY_SEVERITY_* notification constants. o $message - Passed if a descriptive message is available for the event. o $message_code - Passed if a descriptive message code is available for the event. The meaning of this value is dependent on the specific wrapper in use. o $bytes_transferred - If applicable, the $bytes_transferred will be populated. o $bytes_max - If applicable, the $bytes_max will be populated. RETURN VALUES
No value is returned. EXAMPLES
Example #1 stream_notification_callback(3) example <?php function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) { switch($notification_code) { case STREAM_NOTIFY_RESOLVE: case STREAM_NOTIFY_AUTH_REQUIRED: case STREAM_NOTIFY_COMPLETED: case STREAM_NOTIFY_FAILURE: case STREAM_NOTIFY_AUTH_RESULT: var_dump($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max); /* Ignore */ break; case STREAM_NOTIFY_REDIRECTED: echo "Being redirected to: ", $message; break; case STREAM_NOTIFY_CONNECT: echo "Connected..."; break; case STREAM_NOTIFY_FILE_SIZE_IS: echo "Got the filesize: ", $bytes_max; break; case STREAM_NOTIFY_MIME_TYPE_IS: echo "Found the mime-type: ", $message; break; case STREAM_NOTIFY_PROGRESS: echo "Made some progress, downloaded ", $bytes_transferred, " so far"; break; } echo " "; } $ctx = stream_context_create(); stream_context_set_params($ctx, array("notification" => "stream_notification_callback")); file_get_contents("http://php.net/contact", false, $ctx); ?> The above example will output something similar to: Connected... Found the mime-type: text/html; charset=utf-8 Being redirected to: http://no.php.net/contact Connected... Got the filesize: 0 Found the mime-type: text/html; charset=utf-8 Being redirected to: http://no.php.net/contact.php Connected... Got the filesize: 4589 Found the mime-type: text/html;charset=utf-8 Made some progress, downloaded 0 so far Made some progress, downloaded 0 so far Made some progress, downloaded 0 so far Made some progress, downloaded 1440 so far Made some progress, downloaded 2880 so far Made some progress, downloaded 4320 so far Made some progress, downloaded 5760 so far Made some progress, downloaded 6381 so far Made some progress, downloaded 7002 so far Example #2 Simple progressbar for commandline download client <?php function usage($argv) { echo "Usage: "; printf(" php %s <http://example.com/file> <localfile> ", $argv[0]); exit(1); } function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) { static $filesize = null; switch($notification_code) { case STREAM_NOTIFY_RESOLVE: case STREAM_NOTIFY_AUTH_REQUIRED: case STREAM_NOTIFY_COMPLETED: case STREAM_NOTIFY_FAILURE: case STREAM_NOTIFY_AUTH_RESULT: /* Ignore */ break; case STREAM_NOTIFY_REDIRECTED: echo "Being redirected to: ", $message, " "; break; case STREAM_NOTIFY_CONNECT: echo "Connected... "; break; case STREAM_NOTIFY_FILE_SIZE_IS: $filesize = $bytes_max; echo "Filesize: ", $filesize, " "; break; case STREAM_NOTIFY_MIME_TYPE_IS: echo "Mime-type: ", $message, " "; break; case STREAM_NOTIFY_PROGRESS: if ($bytes_transferred > 0) { if (!isset($filesize)) { printf(" Unknown filesize.. %2d kb done..", $bytes_transferred/1024); } else { $length = (int)(($bytes_transferred/$filesize)*100); printf(" [%-100s] %d%% (%2d/%2d kb)", str_repeat("=", $length). ">", $length, ($bytes_transferred/1024), $filesize/1024); } } break; } } isset($argv[1], $argv[2]) or usage($argv); $ctx = stream_context_create(); stream_context_set_params($ctx, array("notification" => "stream_notification_callback")); $fp = fopen($argv[1], "r", false, $ctx); if (is_resource($fp) && file_put_contents($argv[2], $fp)) { echo " Done! "; exit(0); } $err = error_get_last(); echo " Errrrrorr.. ", $err["message"], " "; exit(1); ?> Executing the example above with: php -n fetch.php http://no2.php.net/get/php-5-LATEST.tar.bz2/from/this/mirror php-latest.tar.bz2 will output something similar too: Connected... Mime-type: text/html; charset=utf-8 Being redirected to: http://no2.php.net/distributions/php-5.2.5.tar.bz2 Connected... Filesize: 7773024 Mime-type: application/octet-stream [========================================> ] 40% (3076/7590 kb) SEE ALSO
"Context parameters". PHP Documentation Group STREAM_NOTIFICATION_CALLBACK(3)
All times are GMT -4. The time now is 11:25 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy