* integers into strings
@ 2006-02-02 1:38 isaac_2004
2006-02-02 2:15 ` Jeffrey R. Carter
0 siblings, 1 reply; 5+ messages in thread
From: isaac_2004 @ 2006-02-02 1:38 UTC (permalink / raw)
hi im new to ada and i want to take a number inputted from a user and
seperate the digits then arrange it in ascending and descending order
and subtract and ascending number from the descending number
for example
user inputs 7319
program outputs 9731 - 1379 = 8352
8532 - 2358 = 6174
and so on
also loop it until number acquired after subtraction is the same as
starting number
like this
6174
7641 - 1467 = 6174
what procedure would i use to do this
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: integers into strings
2006-02-02 1:38 integers into strings isaac_2004
@ 2006-02-02 2:15 ` Jeffrey R. Carter
2006-02-02 3:43 ` isaac2004
0 siblings, 1 reply; 5+ messages in thread
From: Jeffrey R. Carter @ 2006-02-02 2:15 UTC (permalink / raw)
isaac_2004@yahoo.com wrote:
> hi im new to ada and i want to take a number inputted from a user and
> seperate the digits then arrange it in ascending and descending order
> and subtract and ascending number from the descending number
>
> for example
>
> user inputs 7319
>
> program outputs 9731 - 1379 = 8352
'Image converts a scalar into a String; 'Value works the other way.
Integer'Image (7319) = " 7319". Integer'Value ("9731") = 9731.
However, if you're getting the number from input, you could just input it as a
String and skip the 1st step.
--
Jeff Carter
"My name is Jim, but most people call me ... Jim."
Blazing Saddles
39
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: integers into strings
2006-02-02 2:15 ` Jeffrey R. Carter
@ 2006-02-02 3:43 ` isaac2004
2006-02-02 5:48 ` Simon Wright
2006-02-02 19:32 ` Jeffrey R. Carter
0 siblings, 2 replies; 5+ messages in thread
From: isaac2004 @ 2006-02-02 3:43 UTC (permalink / raw)
no im not converting the inputted number into a string im sorting the
digits of the value into ascending and descending order and then making
two different numbers out of it one ascending one descending
oh boys look what i found
hey where are the white women at
Blazing Saddles
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: integers into strings
2006-02-02 3:43 ` isaac2004
@ 2006-02-02 5:48 ` Simon Wright
2006-02-02 19:32 ` Jeffrey R. Carter
1 sibling, 0 replies; 5+ messages in thread
From: Simon Wright @ 2006-02-02 5:48 UTC (permalink / raw)
"isaac2004" <isaac_2004@yahoo.com> writes:
> no im not converting the inputted number into a string im sorting
> the digits of the value into ascending and descending order and then
> making two different numbers out of it one ascending one descending
The input is a string.
A string is an array of characters, so if you can sort an array you
can sort a string. I don't know what the point of this exercise is for
you but some hints on how you might use attributes to help make a
function that sorts a string of arbitrary length are in this ..
with Ada.Text_IO; use Ada.Text_IO;
procedure Isaac is
Input : constant String := "1234";
Output : String (1 .. Input'Length);
begin
for I in Input'Range loop
Output (Output'Last - (I - Input'First)) := Input (I);
end loop;
Put_Line (Output);
end Isaac;
Once you have a string, you can convert it to an integer using
Integer'Value:
Result : constant Integer := Integer'Value (Output);
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: integers into strings
2006-02-02 3:43 ` isaac2004
2006-02-02 5:48 ` Simon Wright
@ 2006-02-02 19:32 ` Jeffrey R. Carter
1 sibling, 0 replies; 5+ messages in thread
From: Jeffrey R. Carter @ 2006-02-02 19:32 UTC (permalink / raw)
isaac2004 wrote:
> no im not converting the inputted number into a string im sorting the
> digits of the value into ascending and descending order and then making
> two different numbers out of it one ascending one descending
I suppose you could pull off the digits using "rem" and "/", sort those, and put
them back together using "*" and "+", but it seems easier to deal with the
numbers as Strings and the digits as Characters.
In any case, you're going to input the number as Characters. You may hide this
by using something like Ada.Text_IO.Integer_IO, but the actual input is a
sequence of characters, which is then interpreted as the image of a value of an
integer type and converted to the corresponding value. That's why it's called
"Text I/O". If you do decide to do the sorting with Characters, you can make
things a little easier by simply inputting the number as a String.
--
Jeff Carter
"I would never want to belong to any club that
would have someone like me for a member."
Annie Hall
41
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-02-02 19:32 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-02 1:38 integers into strings isaac_2004
2006-02-02 2:15 ` Jeffrey R. Carter
2006-02-02 3:43 ` isaac2004
2006-02-02 5:48 ` Simon Wright
2006-02-02 19:32 ` Jeffrey R. Carter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox