#include <stdio.h>
   main() {
    double fahr,cel;
    char again;

    do{
    printf("Enter Dgree");
    scanf("%lf",&fahr);
    printf("In Celsius that is %.1lf\n",(fahr-32)*5.0/9.0);
    printf("agian?");
    scanf("%c",&again);
    } while (again =='y');
}

I don't understand why this won't loop
any ideas?

Edited 3 Years Ago by Nick Evan: Fixed formatting

Replace like:

char again[1];
scanf("%c",again);
} while (*again =='y');

But if I put printf after 2nd scanf, its crashing. But the same access in the next line (inside while) is working.
like

main() {
    double fahr,cel;
    char again[1];

    do{
        printf("Enter Dgree : ");
        scanf("%lf",&fahr);
        printf("In Celsius that is %.1lf\n",(fahr-32)*5.0/9.0);
        printf("agian?");
        scanf("%s", again);
        printf("%s", *again);
    } while (*again =='y');
}

Can anyone explain..

Hello xeno86,
Use fflush(stdin) before scanf for again as charley bones said. The loop doesn't work because as you press enter('\n') the '\n' is copied onto the variable again. You can also use flushall() before the scanf() for again.

Edited 5 Years Ago by Arbus: n/a

This question has already been answered. Start a new discussion instead.