• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Weird calculation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Weird calculation


  • Subject: Re: Weird calculation
  • From: Andreas Doerr <email@hidden>
  • Date: Thu, 24 Jan 2002 11:44:33 +0100

> switch([list indexOfSelectedItem]) {
> case 0:
> loesung = wert1 + wert2;
> case 1:
> loesung = wert1 - wert2;
> case 2:
> loesung = wert1 * wert2;
> case 3:
> loesung = wert1 / wert2;
> }
>
> [calc setFloatValue:loesung];
>
> --
>
> Please note that "loesung" stands for the result, "wert1" and "wert2"
> for value 1 and 2. "calc" is the textfield for the result.
>
> The strange thing (for me) is that I always get wrong results!
> Can somebody help me?

I guess that `case 34 works ;-) Your problem has nothing to do with
Coca. Basically you forgot a `break` statement after each calculation.
Cases just serve as labels in C. After the code for one case is done,
execution falls through to the next. So, in your case it is always the
last statement (loesung = wert1 / wert2;) that is executed.

You should have something like

switch([list indexOfSelectedItem]) {
case 0:
loesung = wert1 + wert2;
break;
case 1:
loesung = wert1 - wert2;
break;
case 2:
loesung = wert1 * wert2;
break;
case 3:
loesung = wert1 / wert2;
break;
}

The last break is not strictly necessary. Please note, that it might be
useful to have a `default` clause.

Hope this helps
--Andreas


References: 
 >Weird calculation (From: Thilo Ettelt <email@hidden>)

  • Prev by Date: Re: Weird calculation
  • Next by Date: RE: Weird calculation
  • Previous by thread: Re: Weird calculation
  • Next by thread: Re: Weird calculation
  • Index(es):
    • Date
    • Thread