Thread: Stop if less than 0

  1. #16
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    I think it would be best to stick with what Dweia said.
    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

  2. #17
    Registered User
    Join Date
    Oct 2006
    Posts
    28
    Thank you guys!

  3. #18
    Registered User
    Join Date
    Oct 2006
    Posts
    28
    Hi, I am trying to get this to work, but it won't compile. Please understand I am just the beginner.
    Thanks in advance for any help!



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

  4. #19
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    main() should be int main(void)
    while is in the format while (true statement), which cannot have ; in the ().

    EDIT: You are also using an uninitialized variable fNumber.

  5. #20
    Registered User
    Join Date
    Oct 2006
    Posts
    28
    Still getting this error:

    In function &#226;main&#226;:
    13: error: expected expression before &#226;>&#226; token

    Thank you for help!
    Last edited by Newbie999; 10-20-2006 at 08:26 PM.

  6. #21
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Ah, didn't see that one. . . the comparitive opp is >=, not =>.

  7. #22
    Registered User
    Join Date
    Oct 2006
    Posts
    28
    Still gettiing the same error...

    In function âmainâ:
    13: error: expected â)â before â;â token



    Code:
    #include <stdio.h>
    
    main(void){
    
       float Number;
       int input;
    
       printf("Type an ASCII code 4 through 100 to get their\n");
       printf("correspondent character constants:  ");
       scanf ("%d",& input);
       printf("%8c\n", input);
    
       while ( Number >=4; Number =<100) {
       printf("Icorrect! Number has to be between 4 and 100. TRY again\n");
       scanf("%g",&Number);
                      }
     /* if ( Number>=4;number =<100 ) Don't have to check ) */
      printf("Thank you for entering the number %g!\n", Number);
      }
    Last edited by Newbie999; 10-20-2006 at 08:26 PM.

  8. #23
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Code:
    while ( Number >=4; Number =<100) {
    There is no operator =<, and what is the semicolon supposed to do for you?

    What do input and Number have to do with one another? And do you know that %g is used with floating point values?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  9. #24
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    See #19

    EDIT: Beaten. Bummer.

  10. #25
    Registered User
    Join Date
    Oct 2006
    Posts
    28
    Thanks Dave_Sinkula and Kennedy!
    As you can see, I am just the beginner, trying to learn on my own....
    I made some changes in the code, but still won't compile. I am just very confused.
    I appreciate your help!


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

  11. #26
    Registered User
    Join Date
    Oct 2006
    Posts
    28
    O.K now it compiled, but it won't convert the ASCII codes...
    Can anyone help please?
    Thanks!

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

  12. #27
    Registered User
    Join Date
    Sep 2006
    Posts
    15
    Hey, hey... You cannot use two expression within the while loop's brackets. Remember the syntax for while loop:

    Code:
    while(expression)
    {
         statements;
    }
    So, you can only write either 'Number >= 4' or 'Number >= 100' in the brackets. Ow yeah, you the variable's name should come out first before the value--> 'Number >=100', not '100>=Number'....

  13. #28
    Registered User
    Join Date
    Oct 2006
    Posts
    28
    If I can use ony one expression, How can I then convert the decimal ASCII codes 4 through 100 to their correspondent character constant?

    Thanks for your help!

  14. #29
    Registered User
    Join Date
    Sep 2006
    Posts
    15
    Hello,

    You should use integer data type for number. Otherwise, it wouldn't be able to be converted to character using %c. So, use int Number and replace all %g with %d for integer. OK?

    Hmm, actually what do u expect by writing :

    Code:
    printf("Icorrect! Number has to be between 4 and 100. TRY again\n");
    scanf("%g",&Number);
    Let's see... if u want to ask the user again after he has entered wrong number, you can use a do-while loop which covers the whole thing from entering number to the end. And then, put a condition/expression that will keep on asking the user if the entered number is not between 4 and 100, such as:

    Code:
    do
    {
           statements;
    } while( Number < 4 || Number > 100);
    Note that: || is a an OR operator.

    TRY AGAIN! Do not give up!

  15. #30
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Why are you using a float? Read an integer. Or better yet, just use a char.

    Why are you checking for >= 100, since 100 is allowed. You just told them 100 is ok. Now your ugly loop prevents 100.

    Why are you using %g to print? That won't print a character. Use %c for chatacters. Go read the format specifiers.

    [edit]
    Curses, foiled again!
    [/edit]


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

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