New to Ada, noticing something strange.



Here is an excerpt of my code. Every function works as it should, the
program is set up correct, and the correct values are being passed to
all functions.

The idea of the program is perform arithmetic on arbitrarily long
integers that are inputted as strings using the paper and pencil
approach (digit by digit, from right from right to left, with a carry
digit). The user will enter a base, operand1, and operan2 via command
line arguments. (if you need more explanation let me know).

with Ada.Text_IO;
with Ada.Integer_Text_IO;
with Ada.Command_Line;
with Ada.Strings.Unbounded;
with Ada.Characters.Handling;

use Ada.Text_IO;
use Ada.Integer_Text_IO;
use Ada.Command_Line;
use Ada.Strings.Unbounded;

procedure BigInts is
....

charMap: array (Character) of Integer;

charMap('0') := 0;
charMap('1') := 1;
charMap('2') := 2;
....
charMap('E') := 14;
charMap('F') := 15;

function C2C(strChar: String) return Character is
begin
Put_Line(strChar);
case Integer'Value(strChar) is
when 10 => return 'A';
when 11 => return 'B';
when 12 => return 'C';
when 13 => return 'D';
when 14 => return 'E';
when 15 => return 'F';
when others => return strChar(1);
end case;
end C2C;

function AddDigits(op1, op2: Character) return Character is
begin
charDigit:=C2C(Integer'Image(charMap(op1)+charMap(op2)+carry));

Put("Print1: ");
Put(C2C(Integer'Image(charMap(op1)+charMap(op2)+carry)));

if(charMap(op1)+charMap(op2)+carry)>(charMap(charBase)-1) then
Put_Line("here1: ");

--Set the digit to the highest possible values
charDigit:=C2C(Integer'Image(charMap(charBase)-1));

--carry is all of the rest
carry:=(charMap(op1)+charMap(op2)+carry)-(charMap(charBase)-1);
else
Put_Line("here2: ");
carry:=0; --there is no carry
end if;

Put("Digit: ");
Put(charDigit);
New_Line;
Put("Carry: ");
Put(carry);
New_Line;
return charDigit;
end AddDigits;
....
end BigInts;

(I removed some extra white space so it would align better in the post)

I have some Put()/Put_Line() statements in AddDigits() for debugging
purposes. The problem is in Convert2Character(), nothing was ever
being returned by that function. I added the Put_Line(strChar) to make
sure a correct value was being passed to it. Once I added that
Put_Line() a value was being returned by the function and it was
correct. It seems that a Put_Line() is needed for some reason or it
does not do what it is supposed to do.

.



Relevant Pages

  • Re: Fortran decimal anyone?
    ... One Decimal Digit per Byte Data Formats. ... In some cases, the sign indication, if present, was a separate ... character -- a minus sign or a plus sign in the ... A leading separate character as in, ...
    (comp.lang.fortran)
  • RE: Excel column width question again
    ... do not need to determine what font and point size to use. ... Truncate(128/{Maximum Digit Width}))/256)*)' to ... 100+0.5)/100 to convert pixel to character number. ... Microsoft Online Community Support ...
    (microsoft.public.office.developer.com.add_ins)
  • Re: embarrassing spaghetti code needs stylistic advice
    ... assumes that there is a character in CH which ... necessary using RCH, and it calls RCH at least once so that, when it ... You seem very worried about reading in an EOF character. ... Either '+' is followed by a digit, ...
    (comp.lang.c)
  • Re: Mod 43 Check Digit calculator
    ... miscalculation of the check digit. ... > response to you) should return the check character itself rather than> the ... Here is that formula with the absolute reference problem> that ... > space in the encoding string at the 39th position. ...
    (microsoft.public.excel.programming)
  • Re: Need Help.
    ... '0') from a character to change it to a number, do your calculation, and add 30h to the number to make it a character before displaying it. ... If you want to accept multiple digit numbers as input... ... Once you can display a correct answer all the way up to 9 + 9, I think you'll find it easy to extend it to multiplication. ...
    (comp.lang.asm.x86)