Thread: Else Function not working

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

    Else Function not working

    Hi Guys,

    Im new here and was looking for some help. No matter what I do the else will not print my error message. Any advice? Thanks.

    Code:
    while
    (student > 0)
    
        {
    
        printf (
    "Enter 3 grades for student %d\n", studentID);
    
        scanf  (
    "%f %f %f",&finalexam, &midterm, &homework);
    
            
    if (finalexam <= 100 || finalexam >= 0 || midterm <= 75 || midterm >= 0 || homework  <= 120 || homework >= 0)
    
                {
    
                finalgrade = schoolgrade(finalexam, midterm, homework);
    
                useroutput(finalexam, midterm, homework, finalgrade);
    
                system (
    "pause");
    
                student--;
    
                studentID++;
    
                }
    
            
    else
    
            {
    
            printf(
    "Incorrect value entered \n");
    
            }
    



  2. #2
    Registered User
    Join Date
    Nov 2011
    Location
    Saratoga, California, USA
    Posts
    334
    Well, in order for the else to execute, ALL of the conditional expressions would have to be false since you've used OR. You probably meant && which would go to the else if ANY of the expressions were false.

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    41
    Thank you so much, that was it lol before I originally had && but switched to || when i add the second condition where the variable has to be greater than 0. Thanks again so much been stuck on this for 2 days lol

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function not working how it should.
    By snoikey in forum C Programming
    Replies: 7
    Last Post: 08-23-2010, 02:51 AM
  2. Function not working
    By Tom.b in forum C Programming
    Replies: 8
    Last Post: 10-05-2009, 01:12 PM
  3. why this function is not working
    By chintugavali in forum C++ Programming
    Replies: 6
    Last Post: 01-07-2008, 12:35 AM
  4. Function not working
    By sloopy in forum C Programming
    Replies: 31
    Last Post: 11-12-2005, 08:08 PM
  5. need help getting this function working
    By bobish in forum Game Programming
    Replies: 4
    Last Post: 05-05-2002, 12:42 PM