-
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.
- Loading branch information
1 parent
2f42764
commit 32fcb15
Showing
6 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "../displays/ansi_color_codes.h" | ||
#include "../displays/clear_screen.h" | ||
#include "../displays/escape_sequence.h" | ||
|
||
void rankine_description(void) { | ||
add_new_tab(); | ||
printf("%s--------------------------------------------------%s", BLUE, RESET); | ||
add_new_line(); | ||
add_new_line(); | ||
add_new_tab(); | ||
add_new_tab(); | ||
printf(" %sRankine (°R) to Other Scale%s", GREEN, RESET); | ||
add_new_line(); | ||
add_new_line(); | ||
add_new_tab(); | ||
printf("%s--------------------------------------------------%s", BLUE, RESET); | ||
} |
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,7 @@ | ||
#ifndef RANKINE_DESCRIPTION_H | ||
#define RANKINE_DESCRIPTION_H | ||
#include "rankine_description.c" | ||
|
||
extern void rankine_description(void); | ||
|
||
#endif |
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,86 @@ | ||
#include "../displays/ansi_color_codes.h" | ||
#include "../displays/clear_screen.h" | ||
#include "../displays/escape_sequence.h" | ||
#include "check_valid_input.h" | ||
#include "rankine_description.h" | ||
|
||
void rankine_option(void) { | ||
char *rankine_string = malloc(sizeof(char) * 50); | ||
int invalid_input = 0; | ||
char *garbage_buffer = malloc(sizeof(char) * 50); | ||
int try_again = 0; | ||
|
||
while (1) { | ||
// Clean up the terminal. | ||
clear_screen(); | ||
add_new_line(); | ||
add_new_line(); | ||
|
||
// Display the option description. | ||
rankine_description(); | ||
add_new_line(); | ||
add_new_line(); | ||
|
||
// Display the error message. | ||
if (invalid_input) { | ||
add_new_tab(); | ||
printf(" %sInvalid input. Please try again.%s", RED, RESET); | ||
add_new_line(); | ||
add_new_line(); | ||
} | ||
|
||
// Ask the input. | ||
add_new_tab(); | ||
printf(" Rankine (°R) : "); | ||
scanf("%s", rankine_string); | ||
fgets(garbage_buffer, 50, stdin); | ||
|
||
// Check if input is valid. | ||
int valid_input = check_valid_input(rankine_string); | ||
if (valid_input == 0) { | ||
invalid_input = 1; | ||
continue; | ||
} else { | ||
invalid_input = 0; | ||
} | ||
|
||
// Convert the rankine string input to double. | ||
double rankine_double = atof(rankine_string); | ||
|
||
// Handle computation for celsius scale. | ||
double celsius = (rankine_double - 491.67) * (5.0 / 9.0); | ||
add_new_tab(); | ||
printf(" %sCelsius (°C)%s : %s%.4lf (°C)%s ", BLUE, RESET, YELLOW, | ||
celsius, RESET); | ||
add_new_line(); | ||
|
||
// Handle computation for fahrenheit scale. | ||
double fahrenheit = rankine_double - 459.67; | ||
add_new_tab(); | ||
printf(" %sFahrenheit (°F)%s : %s%.4lf (°F)%s", BLUE, RESET, YELLOW, | ||
fahrenheit, RESET); | ||
add_new_line(); | ||
|
||
// Handle computation for kelvin scale. | ||
double kelvin = rankine_double * (5.0 / 9.0); | ||
add_new_tab(); | ||
printf(" %sKelvin (°K)%s : %s%.4lf (°K)%s", BLUE, RESET, YELLOW, | ||
kelvin, RESET); | ||
add_new_line(); | ||
add_new_line(); | ||
|
||
// Ask user if want to try again. | ||
add_new_tab(); | ||
printf(" Try again (1-yes, 0-no): "); | ||
scanf("%d", &try_again); | ||
fgets(garbage_buffer, 50, stdin); | ||
|
||
// Handle the input of user. | ||
if (try_again == 1) { | ||
invalid_input = 0; | ||
continue; | ||
} else { | ||
break; | ||
} | ||
} | ||
} |
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,7 @@ | ||
#ifndef RANKINE_OPTION_H | ||
#define RANKINE_OPTION_H | ||
#include "rankine_option.c" | ||
|
||
extern void rankine_option(void); | ||
|
||
#endif |