Sinisterly
[C]Do loop prob - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: C, C++, & Obj-C (https://sinister.ly/Forum-C-C-Obj-C)
+--- Thread: [C]Do loop prob (/Thread-C-Do-loop-prob)



[C]Do loop prob - 1llusion - 05-13-2011

Hey! So, I have another noob question, I'm learning the DO loop... well... I have this code:
Code:
main() {
    char another;
    int num;
    do
    {
        printf("\nEnter a number: ");
        scanf("%d", &num);
        printf("Square of %d is %d", num, num * num);
        printf("\nWant to enter another number y/n? ");
        scanf("%c",&another);
    }while(another == 'y');
}

well... when I execute the code, this happens:
=> I'm asked to enter a number
=> A square of the number is printed
=> It asks me if I want to enter another number
=> The program exits ...

Well... where is the prob? Thanks!!!


RE: [C]Do loop prob - jammy7777 - 10-08-2011

use %s here instead of %c.
ex:- scanf("%s",&another);


RE: [C]Do loop prob - Dashing Dante - 10-09-2011

Just add getch(); before the final } .