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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,aceef612e0190367 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-03-23 04:44:59 PST From: dis00109 Newsgroups: comp.lang.ada Subject: Re: Integer? float? confused... Date: Fri, 23 Mar 2001 12:08:00 +0000 Organization: University of Portsmouth Message-ID: <3ABB3C9F.6C9A288A@port.ac.uk> References: <998i7d$19j21@tech.port.ac.uk> NNTP-Posting-Host: c58.csm.port.ac.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.75 [en] (Win95; U) X-Accept-Language: en Path: supernews.google.com!sn-xit-02!supernews.com!news.gv.tsc.tdk.com!news.iac.net!news-out.cwix.com!newsfeed.cwix.com!newsfeed.icl.net!newsfeed.icl.net!newspeer.clara.net!news.clara.net!nntp.news.xara.net!xara.net!gxn.net!server6.netnews.ja.net!server4.netnews.ja.net!server2.netnews.ja.net!news-spool.soton.ac.uk!news.ecs.soton.ac.uk!news.port.ac.uk!news Xref: supernews.google.com comp.lang.ada:6020 Date: 2001-03-23T12:08:00+00:00 List-Id: WM wrote: > I have written a program to calculate Sin. The compiler(AdaGIDE 6.23) said: > "expected type standard.float", why? Please piont out errors, Thanks. > > with Ada.Text_Io, Ada.Integer_Text_Io,Ada.Float_Text_Io; > use Ada.Text_Io, Ada.Integer_Text_Io,Ada.Float_Text_Io; > > procedure sin is > sin_result : float; > i : integer; > function Calc_Sin (Num : Integer) return float is > begin > Sin_Result := Num - (Num ** 3) / 6 + (Num ** 5) / 120; > return Sin_Result; > end Calc_Sin; > > begin > > put("input int: "); > get(i); > Sin_Result := Calc_Sin(Num=>i); > Put(Item=>Sin_Result, Fore=>1, Aft=>4, Exp=>0); > > end sin; Your problem is that you have correctly defined the result as a float (Sin_Result:Float) however you need to convert the data from an integer to a float as you perform the function on it. This mean that instead of writing: Sin_Result := Num - (Num ** 3) / 6 + (Num ** 5) / 120; you want to be writing: Sin_Result:=Float(Num - (Num ** 3) / 6 + (Num ** 5) / 120); This will solve your problem however don't forget to convert the integer to radians before applying Sine to them (1 degree = pi / 180 therefore 90 degrees = 1.57 radians).