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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:23:50+00:00 2026-06-14T12:23:50+00:00

I have a section of code that changes the value of a parameter based

  • 0

I have a section of code that changes the value of a parameter based on the desired input and output that has been chosen. So in the below example, I calculate the volume of a sphere then depending on the units the user used for the input and the units the user chose for the output the number is manipulated accordingly.

My problem is that all my if statements are returning false and the number 10 (from the else) is coming through regardless of what is chosen. I have printed out the value of inputPref and outputPref and they look exactly equal to “mm” and “cubic cm” (for example) and yet still won’t be captured by the if statements.

Any obvious errors? The two variables “inputPref” and “outputPref” are loaded from shared preferences if that helps!

double volumeBase = 4 * piDouble * radius * radius * radius / 3;

                double volume;
                if(inputPref.equals("mm") || outputPref.equals("cubic cm"))
                {
                    volume = volumeBase / 1000;
                }
                if(inputPref.equals("mm") || outputPref.equals("cubic metres"))
                {
                    volume = volumeBase / 1000000000;
                }
                if(inputPref.equals("cm") || outputPref.equals("cubic mm"))
                {
                    volume = volumeBase * 1000;
                }
                if(inputPref.equals("cm") || outputPref.equals("cubic metres"))
                {
                    volume = volumeBase / 1000000;
                }
                if(inputPref.equals("metres") || outputPref.equals("cubic mm"))
                {
                    volume = volumeBase * 1000000000;
                }
                if(inputPref.equals("metres") || outputPref.equals("cubic cm"))
                {
                    volume = volumeBase * 1000000;
                }
                else
                {
                    volume = 10;
                }
  • 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-06-14T12:23:52+00:00Added an answer on June 14, 2026 at 12:23 pm

    All your if statements (except the first one) should be else if statements, so that it only chooses 1 out of all your options.

    As it stands, your code may be evaluating an if statement early on, but it is getting overwritten by the last if-else at the very end, which is almost always going to return 10.

    As pointed out in the comments, you’re probably also meaning to use && instead of || so that you’re running the code when both conditions match in each if or else if statement. You might also consider using equalsIgnoreCase() instead of equals(), so that the case of the users input doesn’t matter.

    It should be…

    double volumeBase = 4 * piDouble * radius * radius * radius / 3;
    
    double volume;
    if(inputPref.equalsIgnoreCase("mm") && outputPref.equalsIgnoreCase("cubic cm")){
        volume = volumeBase / 1000;
    }
    else if(inputPref.equalsIgnoreCase("mm") && outputPref.equalsIgnoreCase("cubic metres")){
        volume = volumeBase / 1000000000;
    }
    else if(inputPref.equalsIgnoreCase("cm") && outputPref.equalsIgnoreCase("cubic mm")){
        volume = volumeBase * 1000;
    }
    else if(inputPref.equalsIgnoreCase("cm") && outputPref.equalsIgnoreCase("cubic metres")){
        volume = volumeBase / 1000000;
    }
    else if(inputPref.equalsIgnoreCase("metres") && outputPref.equalsIgnoreCase("cubic mm")){
        volume = volumeBase * 1000000000;
    }
    else if(inputPref.equalsIgnoreCase("metres") && outputPref.equalsIgnoreCase("cubic cm")){
        volume = volumeBase * 1000000;
    }
    else {
        volume = 10;
    }
    

    If it still isn’t working, it might be a problem with the code where you’re reading the user input.

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

Sidebar

Related Questions

I have a section of code that can be summarised as follows; void MyFunc()
I have the following section of code in an app that I am writing:
Javascript I have code that will hide various sections in a MS CRM form
I have a section of code which should be executed by a maximum number
I have this view (DetailsContainer, first class in code section of this question) with
I have some VERY simple code to return the title for a section header:
In my xaml code, inside the Window.Resources section, I have defined a Data Template
I have this section of code: int numberStars =0; int counter =0; while (file.hasNext())
I have this function in my Javascript Code that updates html fields with their
I have a block of code that opens and closes a registry key to

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.