From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,37c1f61bd0b7914 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!news.belwue.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Converting Type Characters to type string Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <8f5967a7-17ab-4eda-80fc-5cb58ae011f5@s50g2000hsb.googlegroups.com> <2d291584-9cb9-4a3f-8626-7b7066e60566@59g2000hsb.googlegroups.com> <5052229e-61c3-401d-93b6-a95edee29e58@m71g2000hse.googlegroups.com> Date: Mon, 31 Mar 2008 17:45:21 +0200 Message-ID: NNTP-Posting-Date: 31 Mar 2008 17:45:25 CEST NNTP-Posting-Host: fe011ee3.newsspool4.arcor-online.net X-Trace: DXC=DReeO@^L5YKX36K@\WTHGJ4IUKBIk];WbK7h6B[6LHn;2LCVN[ On Mon, 31 Mar 2008 07:44:52 -0700 (PDT), jedivaughn wrote: > Ok, Let me start over. Maybe I'm not approaching my problem the right > way. I'm trying to write a program that converts integers to roman > numerals or vice versa depending on the user input. to do this I > thought I would get the input in separate characters so that I can > easily compare the values to find whether the user inputed IX or XI or > something else. This works until unless the user wants to convert an > integer to roman numeral. to change the input to an integer I'm using > this int:=Integer'Value(str); But for this to work the input has to be > in a string not a character. I thought about taking the input as a > string and then doing a string slice on the characters and storing > them in different variables but once again I'm not sure how many > characters will be entered so how can I do that? So how would be the > optimal way of going about this? Sorry, I still do not understand the problem. You read a line. Then you skip spaces there. Then you try to parse an integer number starting from that position. If that fails you try to parse a Roman number. After successful parsing you advance to the position following the number and skip spaces again. Then you check if the whole like was matched. That's it. Here is a complete program: -------------------------- with Ada.Text_IO; use Ada.Text_IO; with Strings_Edit.Integers; use Strings_Edit.Integers; with Strings_Edit.Roman_Edit; use Strings_Edit.Roman_Edit; procedure Arabic_Roman_Converter is begin loop Put_Line ("Enter a number:"); declare Input : constant String := Get_Line; Number : Integer; begin exit when Input'Length = 0; begin Number := Value (Input); Put_Line ("You typed " & Image (Roman (Number))); exception when End_Error => -- OK, no integer here, maybe it is a Roman number? Number := Integer (Roman'(Value (Input))); Put_Line ("You typed " & Image (Number)); end; exception when Data_Error => Put_Line ("Bad input, possibly syntax or several numbers"); when Constraint_Error => Put_Line ("The number is too large"); when End_Error => Put_Line ("No any number found"); end; end loop; end Arabic_Roman_Converter; ----------------------------------- Enter a number: II You typed 2 Enter a number: 3 You typed III Enter a number: 1000 You typed M Enter a number: f No any number found Enter a number: -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de