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 557329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:00:53+00:00 2026-05-13T12:00:53+00:00

I have a simple calculator that works, but my problem is if the user

  • 0

I have a simple calculator that works, but my problem is if the user doesn’t input any data into the fields then it still calculates. I thought I could do the following:

if (txtUserName.text == nil || txtUserName2.text == nil || txtUserName3.text == nil || txtUserName4.text == nil || txtUserName5.text == nil)
    {
        //error message 
        lblUserTypedName.text =@"Error - No Field Input";
    }
    else
    {
    lblUserTypedName.text = [[NSString alloc] initWithFormat: @"%2.1f%%", ultimate_risk];
    }

But it’s not working at all. Any help letting me know what I am missing here would be greatly appreciated. I would like to use the || so even if they input all fields except one this will still catch it.

  • 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-13T12:00:54+00:00Added an answer on May 13, 2026 at 12:00 pm

    I would suggest using the length method of NSString to determine if there is any input. so you could use

    if ([txtUserName.text length]== 0 || [txtUserName2.text length]== 0 || [txtUserName3.text length]== 0 || [txtUserName4.text length]== 0 || [txtUserName5.text length]== 0)
    {
        //error message 
        lblUserTypedName.text =@"Error - No Field Input";
    }
    else
    {
    lblUserTypedName.text = [[NSString alloc] initWithFormat: @"%2.1f%%", ultimate_risk];
    }
    

    This will work for both the text property being nil (which is the default value according to the documentation) and the text property being the empty string.

    Also note that this still performs the calculation, it just does not display it. If you want to prevent the calculation you need to move the code to calculate ultimate_risk into the else block.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a coding/maths problem that I need help translating into C#. It's a
I have created a shader that works perfectly in Firefox, but in Chrome the
It sounds like a simple job, but with MapReduce it doesn't seem that straight-forward.
i'm using Moscow ML combined with CGI. I have a site that calculates simple
I have a SQL statement (MS SQL Server 2005) that does a simple calculation
I have coded my calculator in simple mode, I have added a button for
I have simple class with width and height member fields which define number of
I have simple php validation form that is halfway working. If you leave the
I have simple win service, that executes few tasks periodically. How should I pass
I made a program in Xcode, being a simple calculator that takes a first

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.