Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <ctype.h>
- char getType();
- float getInput();
- float CtoF(float C);
- float FtoC(float F);
- void displayFah(float F);
- void displayCel(float C);
- void main() {
- char selection;
- float temperature;
- float convert;
- temperature = getInput();
- selection = getType();
- if (selection == 'C') {```
- convert = CtoF(temperature);
- displayFah(convert);
- }
- else if (selection == 'F') {
- convert = FtoC(temperature);
- displayCel(convert);
- }
- else printf("\nInvalid type.");
- _getch();
- }
- char getType() {
- char input;
- printf("\nPlease specify temperature type: [C]elsius/[F]ahrenheit");
- scanf_s("\r%c", &input, 1);
- input = toupper(input);
- return input;
- }
- float getInput() {
- float input;
- printf("\nPlease enter temperature value: ");
- scanf_s("%f", &input);
- return input;
- }
- void displayFah(float F) {
- printf("\nThe converted temperature is %4.2f Fahrenheit", F);
- }
- void displayCel(float C) {
- printf("\nThe converted temperature is %4.2f Celsius", C);
- }
- float CtoF(float C) {
- return 1.8*C + 32;
- }
- float FtoC(float F) {
- return (F-32)*5/9;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement