> You need to start by thinking about how user input works, it looks like
> you did not think about it before writing this. I would suggest that
> using fgets for input and then checking and using what was entered.
> --
> Flash Gordon
yeah yeah yeah flash gordon, spare me the lecture.
if you are so thoughtful,
why don't you elaborate a little more on your possible solution then?
On May 9, 11:48 am, Flash Gordon <s...@flash-gordon.me.uk> wrote:
> icarus wrote, On 09/05/08 21:57:
>
>
>
> > Hi, this is a simple temperature converter (Fahrenheit to Celsius to
> > Kelvin). Using gcc 4.0.
>
> > The user is supposed to enter q or any other non-character to exit the
> > program.
>
> > Problem with this code:
> > I enter 'q' as soon as the program starts. It hangs.
> > Then run it again. Enter a number, it executes fine. But when I enter
> > q, it repeats last number and it doesn't 'pay attention' to the letter
> > entered.
>
> > Any ideas on how can I fix it? thanks in advance.
>
> > #include <stdio.h>
>
> > const double F_TO_CELS_ONE_EIGHT = 1.8;
> > const double F_TO_CELS_THIRTYTWO = 32.0;
> > const double C_TO_KELVIN = 273.16;
>
> > void Temperatures(double f_temp);
>
> > int main(void){
>
> > double f_temp;
> > char quit;
>
> What value does quit have here since it has never been assigned a value?
>
> > while (quit != "q"){
> > printf("Enter temperature in Fahrenheit (q to quit):
> > ");
> > quit = getchar();
>
> So you have read one character, now you go and call scanf whatever the
> suer input! What happens to the newline you enter at the end of the line?
>
> > scanf("%lf", &f_temp);
>
> <snip>
>
> scanf returns a value, what does it mean?
>
> You need to start by thinking about how user input works, it looks like
> you did not think about it before writing this. I would suggest that
> using fgets for input and then checking and using what was entered.
> --
> Flash Gordon
|