From: Adam Beneschan <adambeneschan@gmail.com>
Subject: Re: Wrong Asignment
Date: Fri, 23 May 2014 16:28:48 -0700 (PDT)
Date: 2014-05-23T16:28:48-07:00 [thread overview]
Message-ID: <1e869da6-f574-4873-8879-220f29f009c3@googlegroups.com> (raw)
In-Reply-To: <ba57f917-1fcf-46cc-8326-ec3917f44ccf@googlegroups.com>
On Friday, May 23, 2014 4:15:26 PM UTC-7, Cedric wrote:
> Hi All,
>
>
>
> I am learning Ada since a few days. In my book is a simple excercise to write a program. It looks like this:
>
> with Text_IO;
> with My_Int_IO;
> with My_Flt_IO;
>
> ----------------------------------------------------------------------
>
> procedure chapter2_programming_projects_1 is
> Celsius : float := 0.0;
> Fahrenheit : float := 0.0;
>
> begin
> -- Input
> Text_IO.Put("Please put in the temperature in Fahrenheit: ");
> My_Flt_IO.Get(Item => Fahrenheit);
>
> -- Processing
>
> Celsius := (5/9) x (Fahrenheit - 32);
The multiplication operator is * (asterisk), not "x".
After you fix this, you will find other errors. Fahrenheit is a float, and 32 is an integer, and Ada doesn't like it when you mix operand types like that. You'll need to change the integers in this expression to floats, like this:
Celsius := (5.0/9.0) * (Fahrenheit - 32.0);
It's actually a good thing that Ada complains about it, because it prevents some misunderstandings. It is very common for new programmers learning C or C++ or Java to try
celsius = (5/9) * (fahrenheit - 32);
and then get on a help forum asking why does it keep outputting 0 for celsius? (It's because 5 and 9 are integers, so the program does integer division which throws away the remainder.)
> Why does this statement result in an binary object?
The error message said "binary operator", not "binary object". A binary operator is an operator like * that takes two operands. It was complaining because it expected a binary operator like *, but you gave it "x" which is an identifier.
-- Adam
next prev parent reply other threads:[~2014-05-23 23:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-23 23:15 Wrong Asignment Cedric
2014-05-23 23:28 ` Adam Beneschan [this message]
2014-05-23 23:34 ` Cedric
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox