Thread: comparing integers

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    40

    comparing integers

    Code:
    flag = 1;
    while(flag == 1)
    {
        printf("What is the student's Assignment 1 mark? :");
        scanf("%d",&a1);
    
    
        if((a1>100)&&(a1<0))
    {
        printf("Invalid mark. Please enter again\n");
        flag = 1;
    }
    else
    {
            flag = 0;
    }
    }
    I'm trying see if the input integer is bigger than 100 and less than 0.
    If it's so, then it prints invalid mark and it goes back to input section.
    I made the above sample code to test this thing, but it's not working.
    Could anyone help me with fixing this problem?

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    you should be testing OR using ||
    The value can't possibly be bigger than 100 AND less than 0 can it.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    40
    Oh my god.... Oh yeah!! You are absolutely right! I was being stupid haha.
    Thank you very much for your help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 03-26-2012, 10:50 AM
  2. Comparing two sets of integers
    By bertazoid in forum C Programming
    Replies: 10
    Last Post: 11-26-2008, 07:37 AM
  3. Comparing integers
    By jw232 in forum C++ Programming
    Replies: 17
    Last Post: 04-01-2008, 11:36 AM
  4. sum of integers
    By campermama in forum C++ Programming
    Replies: 12
    Last Post: 06-05-2004, 12:20 AM
  5. Integers
    By Marky_Mark in forum Windows Programming
    Replies: 1
    Last Post: 11-26-2001, 04:56 PM