Author Topic: problem in a program  (Read 450 times)

Offline amit14

  • Single posting newcomer
  • *
  • Posts: 8
problem in a program
« 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
       


Offline stahta01

  • Lives here!
  • ****
  • Posts: 6158
    • My Best Post
Re: problem in a program
« Reply #1 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

Please use code tags in the future
Code: [Select]
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: [Select]
scanf(" %c", &another);
Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Testing, compiling CB Trunk against wxWidgets 3.0.2.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline amit14

  • Single posting newcomer
  • *
  • Posts: 8
Re: problem in a program
« Reply #2 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.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6158
    • My Best Post
Re: problem in a program
« Reply #3 on: December 26, 2017, 04:07:16 pm »
The line below is a hyperlink follow it!
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

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Testing, compiling CB Trunk against wxWidgets 3.0.2.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline amit14

  • Single posting newcomer
  • *
  • Posts: 8
Re: problem in a program
« Reply #4 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
« Last Edit: December 26, 2017, 06:29:56 pm by amit14 »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 10733
    • Travis build status
Re: problem in a program
« Reply #5 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...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7251
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: problem in a program
« Reply #6 on: December 27, 2017, 10:20:19 am »
Topic locked, because it violates our forum rules.