Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: amit14 on December 26, 2017, 05:32:23 am

Title: problem in a program
Post by: amit14 on December 26, 2017, 05:32:23 am
actually I am facing a problem in creating a program. I have recently started learning c, and in the code
main()
{
      char another;
      int num;
      do
      {
        printf("enter a number");
        scan("%d", & num);
        printf("want to enter another no. y/n");
        scanf("%c", &another);
       }while(another=='y');
}
the program ends without accepting the value of y or n
I changed the %c to %d, then it accepted the ASCII values of y and n(121 and 110), instead of the letters.
please help me solve this problem
       

Title: Re: problem in a program
Post by: stahta01 on December 26, 2017, 10:17:50 am
Please read and follow the rules in the future.
http://forums.codeblocks.org/index.php/topic,9996.0.html (http://forums.codeblocks.org/index.php/topic,9996.0.html)

Please use code tags in the future
Code
scanf("%c", &another);

The likely fix of your code; please read up on what a space does in front of "%c" in calling scanf.

Code
scanf(" %c", &another);

Tim S.
Title: Re: problem in a program
Post by: amit14 on December 26, 2017, 03:28:50 pm
thanks
it is solved
well there is one more issue
can u explain me how to make a program for counting the no. of +ve, -ve, and zeroes I entered.
Title: Re: problem in a program
Post by: stahta01 on December 26, 2017, 04:07:16 pm
The line below is a hyperlink follow it!
http://catb.org/~esr/faqs/smart-questions.html (http://catb.org/~esr/faqs/smart-questions.html)

Quote
Be sensitive in choosing where you ask your question. You are likely to be ignored, or written off as a loser, if you:

    post your question to a forum where it's off topic

    post a very elementary question to a forum where advanced technical questions are expected, or vice-versa

    cross-post to too many different newsgroups

    post a personal e-mail to somebody who is neither an acquaintance of yours nor personally responsible for solving your problem

You will likely be banned or this thread locked because you are still posting off topic questions!

Another link to the rules of this site; that, you seem to be unable to follow!
http://forums.codeblocks.org/index.php/topic,9996.0.html (http://forums.codeblocks.org/index.php/topic,9996.0.html)

Tim S.
Title: Re: problem in a program
Post by: amit14 on December 26, 2017, 06:27:08 pm
oh
sorry for this mistake
it means questions related to programming can't be asked on this forum.
then can you suggest me where can I ask these questions
can I inbox you or other users directly
Title: Re: problem in a program
Post by: oBFusCATed on December 26, 2017, 07:22:06 pm
can I inbox you or other users directly
Nope, this is an even worse then asking public questions...
Title: Re: problem in a program
Post by: Jenna on December 27, 2017, 10:20:19 am
Topic locked, because it violates our forum rules (http://forums.codeblocks.org/index.php/topic,9996.0.html).