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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:59:17+00:00 2026-05-16T05:59:17+00:00

I have a program with which dreamlax worked a lot with me on, which

  • 0

I have a program with which dreamlax worked a lot with me on, which uses Objective-C to convert temperatures between the Fahrenheit, Celsius, Kelvin and Rankine temperature scales, but converting console-input into Kelvin, and then from Kelvin to the end-user’s desired temperature scale.

Now, I have an idea I would like to implement for the final prompt of the converted temperatures once the calculations are done. It is set up currently to only display like so:

x degrees temperature-scale

Where x = the final converted temperature, and temperature-scale = the scale the user wishes to have his temperature converted to.

Suppose the end-user selected Fahrenheit as his/her source temperature, wishing to convert 212 degrees into his/her target temperature scale of Celsius. The conversions should equal 100 degrees Celsius obviously, but I think the program would be better of displaying the result like this:

212 degrees Fahrenheit is 100 degrees Celsius.

Now, I’ve made the values that need to be replaced by variables in bold. I have the 212 and 100 values solved easily, because 100 variable has been there in the first place, and 212 can easily be remedied by replacing it with the string formatter of the sourceTemp variable, the variable which contains the users original inputted temperature.

Now, the Fahrenheit string is a bit different.

I have tried to establish something new in the original switch like so:

switch (prompt) 
{
    case 1:
        //end-user chooses Fahrenheit
        [converter setFahrenheitValue:sourceTemp];
        sourceTempText = 1;
        break;

    case 2:
        //end-user chooses Celsius
        [converter setCelsiusValue:sourceTemp];
        sourceTempText = 2;
        break;

    case 3:
        //end-user chooses Kelvin
        [converter setKelvinValue:sourceTemp];
        sourceTempText = 3;
        break;

    case 4:
        //end-user chooses Rankine
        [converter setRankineValue:sourceTemp];
        sourceTempText = 4;
        break;
}

OK, so I have added to each different case, setting a new variable named sourceTempText to either 1-4, the same value that the end-user chose to pick his/her source temperature.

Now, here is how I tried to display the final prompt to the end-user with the final switch:

switch (prompt2) 
{
    case 1:
        //end-user chooses Fahrenheit
        printf("%lf degrees sourceTempText is %lf degrees Fahrenheit\n", sourceTemp, [converter fahrenheitValue]);
        break;

    case 2:
        //end-user chooses Celsius
        printf("%lf degrees sourceTempText is %lf degrees Celsius\n", sourceTemp, [converter celsiusValue]);
        break;

    case 3:
        //end-user chooses Kelvin
        printf("%lf degrees sourceTempText is %lf degrees Kelvin\n", sourceTemp, [converter kelvinValue]);
        break;

    case 4:
        //end-user chooses Rankine
        printf("%lf degrees sourceTempText is %lf degrees Rankine\n", sourceTemp, [converter rankineValue]);
        break;
}

I am not sure now, if I can insert sourceTempText into the string like I have here, instead, maybe I have to use a string formatter, but I’m not sure. It should be an easy fix, I just wanted to throw it out here! 🙂

P.S. sorry for the kind of messy question formatting, I kind of didn’t know how to phrase it so please ask for clarification if needed.

  • 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-16T05:59:18+00:00Added an answer on May 16, 2026 at 5:59 am

    Replace sourceTempText with %s, and above the switch statement declare the possible strings like so:

    char *scales[4] = { "Fahrenheit", "Celsius", "Kelvin", "Rankine" };
    

    Then add and argument to each printf, after the sourceTemp, like so:

    printf("%lf degrees %s is %lf degrees Fahrenheit\n",
                       sourceTemp, scales[prompt-1], [converter fahrenheitValue]);
    

    That’s prompt-1 because counting starts at zero, and you start at 1.


    ps. I see now you set sourceTempText = 1/2/3/4; – I just used prompt, since it has the same value. What you could do, is setting

    char *scales[5] = { "Error!", "Fahrenheit", "Celsius", "Kelvin", "Rankine" };
    

    and using scales[sourceTempText], while making sure that before the switch, sourceTempText = 0. That would make a fine example of input sanitizing: whatever the user manages to put in prompt, your program will always display a valid text.

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

Sidebar

Related Questions

I have a program which needs to behave slightly differently on Tiger than on
I have a program which deliberately performs a divide by zero (and stores the
I have a program which has some Textareas / Labels these can be anywhere
I have a program which needs installing on windows 64 boxes. Most of the
I have a program which only needs a NotifyIcon to work as intended. So
Consider this problem: I have a program which should fetch (let's say) 100 records
I have an AppleScript program which creates XML tags and elements within an Adobe
I have a program in which I've lost the C++ source code. Are there
I have a program in which the user adds multiple objects to a scene.
I have an MPI program which compiles and runs, but I would like 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.