Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


[C]Do loop prob filter_list
Author
Message
[C]Do loop prob #1
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!!!
Staff will never ever ask you for your personal information.
We know everything about you anyway.

Reply

RE: [C]Do loop prob #2
use %s here instead of %c.
ex:- scanf("%s",&another);
[Image: 262s21x.jpg]

Reply

RE: [C]Do loop prob #3
Just add getch(); before the final } .

Reply







Users browsing this thread: 2 Guest(s)