Advertisement
BladeMechanics

Lyle

Sep 25th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.15 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <ctype.h>
  5.  
  6. char getType();
  7. float getInput();
  8. float CtoF(float C);
  9. float FtoC(float F);
  10. void displayFah(float F);
  11. void displayCel(float C);
  12.  
  13. void main() {
  14.     char selection;
  15.     float temperature;
  16.     float convert;
  17.     temperature = getInput();
  18.     selection = getType();
  19.     if (selection == 'C') {```
  20.         convert = CtoF(temperature);
  21.         displayFah(convert);
  22.     }
  23.     else if (selection == 'F') {
  24.         convert = FtoC(temperature);
  25.         displayCel(convert);
  26.     }
  27.     else printf("\nInvalid type.");
  28.         _getch();
  29. }
  30.  
  31. char getType() {
  32.     char input;
  33.     printf("\nPlease specify temperature type: [C]elsius/[F]ahrenheit");
  34.     scanf_s("\r%c", &input, 1);
  35.     input = toupper(input);
  36.     return input;
  37. }
  38.  
  39. float getInput() {
  40.     float input;
  41.     printf("\nPlease enter temperature value: ");
  42.     scanf_s("%f", &input);
  43.     return input;
  44. }
  45.  
  46. void displayFah(float F) {
  47.  
  48.     printf("\nThe converted temperature is %4.2f Fahrenheit", F);
  49. }
  50.  
  51. void displayCel(float C) {
  52.  
  53.     printf("\nThe converted temperature is %4.2f Celsius", C);
  54. }
  55.  
  56. float CtoF(float C) {
  57.     return 1.8*C + 32;
  58. }
  59.  
  60. float FtoC(float F) {
  61.     return (F-32)*5/9;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement