Hi,

Below is code which squares a particular number 12. I want that 
number to be entered by the user. But I do not know how to accept 
integers. Whatever changes I try to make to the code to accept 
 from the user, the value is automatically a char or int. Plz do 
suggest a way in which I can accept integers and do the 
calculation.

:- module accNumSqr.
:- interface.
:- import_module io.

:- pred main(io__state, io__state).
:- mode main(di, uo) is det.

:- implementation.
:- import_module numSqr, char.

main --> io__write_string("The number to be squared: 12 \n"),
         {numSqr(N, X)},
         io__write_string(" Squared number is : \n"),
         io__write_int(X),
         io__nl.
---------------------------------------------------------------
:- module numSqr.

:- interface.
:- pred numSqr(int, int).
:- mode numSqr(in, out) is det.

:- implementation.
:- import_module int.
numSqr(N,S) :-
         ( if N = 0 then
                 S = 0
         else
                 S = N * N
         ).
:- end_module numSqr.


Plz do suggest. Thanks.

Regards,

Noel
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users@cs.mu.oz.au
administrative address: owner-mercury-users@cs.mu.oz.au
unsubscribe: Address: mercury-users-request@cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request@cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------

