How can i make the calculator have multiple numbers stored, while calculating?

Here are my codes but it seems to only store one number at a time. Hope to upgrade it to 2 or more numbers. I’m not to sure if if it’s alright to modify “else if” statement? Open to ideas, Thank you!

 

       else if sender.tag == 16 {

          

            if operation == 12{ //Divide

              

                label.text = String(previousNumber / numberOnScreen)

              

            }

              

            else if operation == 13{ //Multiply

              

                label.text = String(previousNumber * numberOnScreen)

              

            }

              

            else if operation == 14{ //Subtract

              

                label.text = String(previousNumber – numberOnScreen)

              

            }

              

            else if operation == 15{ //Add

              

                label.text = String(previousNumber + numberOnScreen)

              

            }

          

        }

          

        else if sender.tag == 11{

          

            label.text = “”

          

            previousNumber = 0;

          

            numberOnScreen = 0;

          

            operation = 0;

Powered by WPeMatico

About

You may also like...

Comments are closed.