Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- int main()
- {
- char choice = ' ';
- char repeat;
- float temp, answer;
- for (;;) {
- for (;;) {
- printf ("Enter 'c' if you want to convert from celcius to farenheit.\n");
- printf ("Enter 'f' if you want to convert from farenheit to celcius.\n: ");
- scanf ("%c", &choice);
- if (choice == 'c') {
- fflush(stdin);
- printf ("Enter the temperature in celcius: ");
- scanf ("%f", &temp);
- answer = (temp*9/5) + 32;
- printf ("The temperature in farenheit is %.2fF\n", answer);
- break;
- } else if (choice == 'f') {
- fflush(stdin);
- printf ("Enter the temperature in farenheit: ");
- scanf ("%f", &temp);
- answer = (temp - 32) * 5/9;
- printf ("The temperature in celcius is %.2fC\n", answer);
- break;
- } else {
- printf ("Wrong input\n");
- fflush(stdin);
- }
- }
- for (;;) {
- fflush(stdin);
- printf ("\nDo another calculation? (y/n)\n");
- scanf ("%c", &repeat);
- if (repeat == 'y') {
- fflush(stdin);
- break;
- } else if (repeat == 'n') {
- return 0;
- } else {
- fflush(stdin);
- printf ("Wrong answer\n");
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement