Created
September 26, 2012 17:27
-
-
Save Browne/3789353 to your computer and use it in GitHub Desktop.
A very simple Ada Calculator - My version of a Hello World
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Written by Eliot Brown on 26th September 2012 | |
| --A basic calculator that can calculate * + - / | |
| --of two real numbers | |
| with TEXT_IO; use TEXT_IO; | |
| procedure CALCULATOR is | |
| type REAL is digits 20; --20 digit numbers | |
| package IO_REAL is new FLOAT_IO(REAL); use IO_REAL; | |
| A, B, C: Real --Declare A, B, C are real. Note, C is the result | |
| OPERAND: CHARACTER; --Declare the operand as a character. + - * / acceptable | |
| begin | |
| while not END_OF_FILE(STANDARD_INPUT) loop | |
| GET(A); GET(OPERAND); GET(B); --read the input | |
| case OPERAND is | |
| when '+' => C := A+B; | |
| when '-' => C := A-B; | |
| when '*' => C := A*B; | |
| when '/' => C := A/B; | |
| when others => PUT("Error, bad operator"); | |
| exit; --Exit only on bad input | |
| end case; | |
| PUT(RESULT);NEW_LINE; | |
| end loop; | |
| end CALCULATOR; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment