Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6053909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:05:35+00:00 2026-05-23T08:05:35+00:00

I have a simple iOS/objective C question. I have searched the forum and have

  • 0

I have a simple iOS/objective C question. I have searched the forum and have tried a couple different approaches but I cant seem to figure this out, I am very new to coding so I apologize for this may seem silly. I am trying to build a simple calculator with buttons made from scratch but I am stuck on the decimal portion. I am using a switch statement to input my numbers through the button (id)sender. You can see the portion I commented out, this is where I was going to take the id tagged with 10 and write some kind of statement to implement a decimal into the float value.

I also looked at a previous post which appends the decimal place. I tried to alter the code but it seems like im missing quite a few things here.

-(IBAction)decimalButton:(id)sender{
    calculatorScreen.text = [calculatorScreen.text stringByAppendingFormat:@"."]; 
}

Any help/suggestions/sample code would be very helpful, again im sorry for the newbie question, im trying my best to learn the basics.

#import "calcViewController.h"

@implementation calcViewController



-(IBAction)buttonDigitPressed:(id)sender { //ditits presed with sender tag
//    switch ([sender tag]) {
//        case 1:
//            currentNumber = 1;
//            break;
//        case 2:
//            currentNumber = 2;
//            break;
//        case 3:
//            currentNumber = 3;
//            break;
//        case 4:
//            currentNumber = 4;
//            break;
//        case 5:
//            currentNumber = 5;
//            break;
//        case 6:
//            currentNumber = 6;
//            break;
//        case 7:
//            currentNumber = 7;
//            break;
//        case 8:
//            currentNumber = 8;
//            break;
//        case 9:
//            currentNumber = 9;
//            break;
//        case 10:
//            //possibly implement decimal here 
//            break;
//    }


    currentNumber = (float)[sender tag]; //sets currentNumber to buttonPressed
    calculatorScreen.text = [NSString stringWithFormat:@"%g",currentNumber];//displays button
}


-(IBAction)buttonOperationPressed:(id)sender {
    //currentOperation is 0 by system default?

    if (currentOperation == 0) 
        result = currentNumber;

    else {
        switch (currentOperation) {
            case 1:
                result = result + currentNumber;
                break;
            case 2:
                result = result - currentNumber;
                break;
            case 3:
                result = result * currentNumber;
                break;
            case 4:
                result = result / currentNumber;
                break;
            case 5:
                currentOperation = 0;
                break;
        }
    }
    //currentNumber = 0;

    currentNumber = result; //current number equals last resulting equation
    calculatorScreen.text = [NSString stringWithFormat:@"%g",result]; //screen prints result
    if ([sender tag] == 0) result = 0;
    currentOperation = [sender tag];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:05:36+00:00Added an answer on May 23, 2026 at 8:05 am

    The code below should update the screen correctly.

    -(IBAction)buttonDigitPressed:(id)sender { //ditits presed with sender tag
        switch ([sender tag]) {
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
            case 8:
            case 9:
                calculatorScreen.text = [calculatorScreen.text stringByAppendingFormat:@"%d", [sender tag]];
                break;
    
            case 10:
                NSRange range = [calculatorScreen.text rangeOfString:@"."];
                if ( range.location == NSNotFound ) {
                    calculatorScreen.text = [calculatorScreen.text stringByAppendingString:@"."];
                }
                break;
        }
    }
    

    To use this in calculations, use

    float screenNumber = [calculatorScreen.text floatValue];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think this is pretty simple but i'm new to Objective-C, IOS and Core
I have lately been developing a very simple app for iOS with PhoneGap. All
am just starting off with restkit for ios. I have a very simple json
First, I am super-new to Objective-C/iOS development and, in fact, this question is for
I have a simple iOS 5 storyboard that contains a tableview controller scene. However,
I wrote simple iOS app which countdown the time til midnight. I have single
I want to learn how to develop for iOS devices, but I don't have
I've just started development of iOS Applications and my question relates to simple arrays.
fairly new to Objective-C and iOS development (coming from PHP) and I have a
I have a very simple iOS app with a uiwebview loading a very simple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.