When comparison between integers is being checked, relational
operators will be used. Relational operators are listed in Table
1.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Comparison of real numbers requires a little caution in
programming. Standard comparisons such as
'A = B' or 'C = 3.14' may not work properly in a program.
The real number may not be stored in memory exactly the way it was entered.
This is computer dependent and may cause problems when a program is executed
on a different machine. Figure 1 shows an example of a simple program,
which was tested on a GNAT compiler, that compares two integers which a
user enters.
| with Ada.Integer_Text_IO, Ada.Text_IO;
use Ada.Integer_Text_IO, Ada.Text_IO; procedure Integer_Compare is First_In, Second_In : Integer; Test : Character := 'C'; begin while Test = 'C' or Test = 'c' loop -- Input comparison to see if user wants to remain in loop New_Line; New_Line; -- 2 carriage returns
if First_In > Second_In then --
Greater than comparison
|
When this program is run it would look like
Enter a whole number: 5
Enter another whole number: 23
23 is larger than
5
Enter 'E' to exit or 'C' to continue:
E
Go to the Tutorial Table of Contents