Thread: Stop if less than 0

  1. #46
    Registered User
    Join Date
    Oct 2006
    Posts
    28
    Can anyone please help?
    I am sure you were all beginners once.
    I tried following all the suggestions.
    This code just won't work....
    Please indicate where I am making mistake...:0(

    I am just a girl trying to learn C...

  2. #47
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Print the number as a character if that's what you're trying to do, as you did in your first printf but not the second.
    Code:
    #include <stdio.h>
    
    main(void){
    
    
      int Number;
    
    
       do{
       printf("Type an ASCII code 4 through 100 to get their\n");
       printf("correspondent character constants:  ");
       scanf("%d",& Number);
       if(Number < 4 || Number > 100)
       printf("\nIncorrect! Number has to be between 4 and 100. TRY again!\n\n");
    
      }
      while(Number < 4 || Number > 100);
        printf("%c\n", Number);
    
       /* if ( Number < 4 || Number > 100 ) Don't have to check ) */
      printf("Thank you for entering the number %c!\n", Number);
      }
    [edit] Why did you choose to limit the number from 4 to 100, by the way? If you're trying to limit the program to printing only printable characters, use the return value of isprint() in <ctype.h>:
    Code:
    #include <ctype.h>
    
    /* ... */
    
    if(!isprint(Number)) printf(/* ... */);
    [/edit]
    Last edited by dwks; 10-21-2006 at 02:59 PM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #48
    Registered User
    Join Date
    Oct 2006
    Posts
    28
    I changed the %c, but when I try to execute it all it does is this:
    Type an ASCII code 4 through 100 to get their
    correspondent character constants: 6

    and then ends....

    Thank you for help!

    Code:
    #include <stdio.h>
    
    main(void){
    
    
      int Number;
    
    
       do{
       printf("Type an ASCII code 4 through 100 to get their\n");
       printf("correspondent character constants:  ");
       scanf("%d",& Number);
       if(Number < 4 || Number > 100)
       printf("\nIncorrect! Number has to be between 4 and 100. TRY again!\n\n");
    
      }
      while(Number < 4 || Number > 100);
        printf("%c\n", Number);
    
       /* if ( Number < 4 || Number > 100 ) Don't have to check ) */
      printf("Thank you for entering the number %c!\n", Number);
      }

  4. #49
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    No it doesn't! Your code works fine!
    Code:
    Type an ASCII code 4 through 100 to get their
    correspondent character constants:  99
    Thank you for entering the number c!
    Oh, and no one cares what gender you are. They only care if you're paying attention. You aren't. You fail.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #50
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    It may end if the windows console dissapears before you can see what it says, but I suspect you would have had that problem with previous programs if that was the case.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #51
    Registered User
    Join Date
    Oct 2006
    Posts
    28
    Well, it wasn't working...I am paying attention...Maybe dwks is right and the window console dissapears before I can see what is says.I will try it on my friend's computer.
    I have two more questions:
    How could I use this loop to repeatedly ask the user to enter a valid decimal number in case input is not between 4 and 100?
    How can I make the program end when the user enters number 3?
    Thanks a lot! )

  7. #52
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Yes it was. No you're not. Read the FAQ. Use a loop. Post your code.


    Quzah.
    Hope is the first step on the road to disappointment.

  8. #53
    Registered User
    Join Date
    Oct 2006
    Posts
    28
    This is my code.
    I have two more questions:
    How could I use a loop to repeatedly ask the user to enter a valid decimal number in case input is not between 4 and 100?
    How can I make the program end when the user enters number 3?
    Thanks a lot!


    Code:
    #include <stdio.h>
    
    main(void){
    
    
      int Number;
    
    
       do{
       printf("Type an ASCII code 4 through 100 to get their\n");
       printf("correspondent character constants:  ");
       scanf("%d",& Number);
       if(Number < 4 || Number > 100)
       printf("\nIncorrect! Number has to be between 4 and 100. TRY again!\n\n");
    
      }
      while(Number < 4 || Number > 100);
        printf("%c\n", Number);
    
       /* if ( Number < 4 || Number > 100 ) Don't have to check ) */
      printf("Thank you for entering the number %c!\n", Number);
      }

  9. #54
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    How could I use a loop to repeatedly ask the user to enter a valid decimal number in case input is not between 4 and 100?
    Seems like you're doing that to me with your do-while loop.

    How can I make the program end when the user enters number 3?
    Hello return 0;. Look at this for a few pointers. Oh, and BTW, main returns an int.

    Also, you may want to check out this and this to see if that resolves any of your console problems.

    Notice, as well, that most of this stuff could be found on the site already. You didn't really need to make a whole thread.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  10. #55
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Quote Originally Posted by Happy_Reaper
    Seems like you're doing that to me with your do-while loop.
    No, she's not. What everyone has been telling you is to "use a loop". What they are trying to tell you is that you'll need a while() / do...while() loop around all your current code. You'll want the start of it before your do, then you'll want the end of it after the print statement. Also, you'll need to control the print statement with an if().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fscanf %s or %d integer input space char stop question...
    By transgalactic2 in forum C Programming
    Replies: 5
    Last Post: 04-14-2009, 10:44 AM
  2. Error stop Http Listener
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 06-04-2008, 02:14 AM
  3. how do I stop text from being erased
    By rakan in forum Windows Programming
    Replies: 2
    Last Post: 02-20-2008, 12:00 AM
  4. when a while loop will stop ?
    By blue_gene in forum C Programming
    Replies: 13
    Last Post: 04-20-2004, 03:45 PM
  5. Telling other applications to stop
    By nickname_changed in forum Windows Programming
    Replies: 11
    Last Post: 09-25-2003, 12:47 AM