Hi, I am very new to C and creating a program converting Celsius to Fahrenheit. I have a "do while" command so the user can loop the program if he/she choose to. The problem is that instead of looping the program it ignores the user input and continue the program.
I hope someone can help me with this problem.
Thanks in advance
Code:
#include <stdio.h>
#include <stdlib.h>
int main ()
{
char temp ;
int tempdegree ;
float tempequals ;
char restart;
do
{
printf("Welcome to fahrenheit to celsius (vice versa) converter!\n\nPress F to convert fahrenheit to celsius or press C to convert celsius to fahrenheight: ") ;
scanf ("%c", &temp);
if (temp=='f' || temp=='F')
{
system("cls");
printf ("Please pick the temperature you want to convert:");
scanf ("%d", &tempdegree);
tempequals=0.555555556*(tempdegree-32);
printf ("%d fahrenheit equals %f celsius.\n\n\nPress r to restart program", tempdegree, tempequals);
scanf ("%c", &restart);
}
else if (temp=='c' || temp=='C')
{
system("cls");
printf ("Please pick the temperature you want to convert:");
scanf ("%d", &tempdegree);
tempequals=(1.8*tempdegree)+32;
printf ("%d celsius equals %f Fahrenheit.\n\n\nPress r to restart program.", tempdegree, tempequals);
scanf ("%c", &restart);
}
} while (restart=='r' || restart=='R'); //instead of looping when inserted "R" the program continues.
getchar ();
return 0;
}