Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.75 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. int main()
  5. {
  6.     char choice = ' ';
  7.     char repeat;
  8.     float temp, answer;
  9.    
  10.     for (;;) {
  11.         for (;;) {
  12.             printf ("Enter 'c' if you want to convert from celcius to farenheit.\n");
  13.             printf ("Enter 'f' if you want to convert from farenheit to celcius.\n: ");
  14.             scanf ("%c", &choice);
  15.            
  16.             if (choice == 'c') {
  17.                        fflush(stdin);
  18.                        printf ("Enter the temperature in celcius: ");
  19.                        scanf ("%f", &temp);
  20.                        answer = (temp*9/5) + 32;
  21.                        printf ("The temperature in farenheit is %.2fF\n", answer);
  22.                        break;
  23.             } else if (choice == 'f') {
  24.                    fflush(stdin);
  25.                        printf ("Enter the temperature in farenheit: ");
  26.                        scanf ("%f", &temp);
  27.                        answer = (temp - 32) * 5/9;
  28.                        printf ("The temperature in celcius is %.2fC\n", answer);
  29.                        break;
  30.             } else {
  31.                        printf ("Wrong input\n");
  32.                        fflush(stdin);
  33.             }
  34.         }
  35.        
  36.            for (;;) {
  37.                fflush(stdin);
  38.                printf ("\nDo another calculation? (y/n)\n");
  39.                scanf ("%c", &repeat);
  40.                if (repeat == 'y') {
  41.                        fflush(stdin);
  42.                        break;
  43.                } else if (repeat == 'n') {
  44.                        return 0;
  45.                } else {
  46.                        fflush(stdin);
  47.                        printf ("Wrong answer\n");
  48.                        
  49.                }
  50.            }
  51.        }
  52.    
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement