-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Rankine to Celsius, Fahrenheit, and Kelvin conversion.
- Loading branch information
1 parent
49ab439
commit 121c3ac
Showing
7 changed files
with
89 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package rankine | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/kentlouisetonino/tempscale/src/displays" | ||
) | ||
|
||
func Conversion() { | ||
var rankineInput float64 | ||
var celsiusInputError bool = false | ||
var conversionMenuInput int | ||
var backToMainMenu bool = false | ||
|
||
for backToMainMenu == false { | ||
// Clear the screen. | ||
displays.ClearScreen() | ||
displays.AddNewline() | ||
displays.AddNewline() | ||
|
||
// Show the description. | ||
displays.FahrenheitOptionDescription() | ||
displays.AddNewline() | ||
|
||
// Error instruction. | ||
if celsiusInputError { | ||
displays.AppOptionInputError() | ||
displays.AddNewline() | ||
} | ||
|
||
// Ask the celsius input. | ||
fmt.Print(displays.Tab, " ", "Rankine (°R)", displays.Tab, displays.Tab, ": ") | ||
_, err := fmt.Scan(&rankineInput) | ||
|
||
if err != nil { | ||
celsiusInputError = true | ||
continue | ||
} | ||
|
||
// Display the equivalent of Celsius to Fahrenheit, Kelvin, Rankine. | ||
fmt.Print(displays.Tab, " ", "Celsius (°C)", displays.Tab, displays.Tab, ": ", displays.ColorGreen, convertToCelsius(rankineInput), displays.ColorReset); | ||
displays.AddNewline() | ||
fmt.Print(displays.Tab, " ", "Fahrenheit (°F)", displays.Tab, ": ", displays.ColorGreen, convertToFahrenheit(rankineInput), displays.ColorReset); | ||
displays.AddNewline() | ||
fmt.Print(displays.Tab, " ", "Kelvin (°K)", displays.Tab, displays.Tab, ": ", displays.ColorGreen, convertToKelvin(rankineInput), displays.ColorReset) | ||
displays.AddNewline() | ||
displays.AddNewline() | ||
|
||
// Ask if user wants to retry or go back to main menu. | ||
fmt.Print(displays.Tab, " ", displays.ColorBlue, "[1-Retry, 2-Back, Any-Exit]", displays.ColorReset, displays.Tab, ": ") | ||
_, err = fmt.Scan(&conversionMenuInput) | ||
|
||
if err != nil { | ||
displays.ClearScreen() | ||
displays.AppExit() | ||
} | ||
|
||
if conversionMenuInput == 1 { | ||
continue | ||
} else if conversionMenuInput == 2 { | ||
backToMainMenu = true | ||
} else { | ||
displays.ClearScreen() | ||
displays.AppExit() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package rankine | ||
|
||
func convertToCelsius(rankine float64) float64 { | ||
return (rankine - 491.67) * (5.0 / 9.0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package rankine | ||
|
||
func convertToFahrenheit(rankine float64) float64 { | ||
return rankine - 459.67 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package rankine | ||
|
||
func convertToKelvin(rankine float64) float64 { | ||
return rankine * (5.0 / 9.0) | ||
} |