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.