expected } before else

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • psychocoyote
    New Member
    • Oct 2011
    • 1

    expected } before else

    Thanks for reading this in advance

    Basically I compile my script and I get this return error
    Code:
    lab05.cpp: In function ‘int main()’:
    lab05.cpp:46: error: expected `}' before ‘else’
    lab05.cpp: At global scope:
    lab05.cpp:46: error: expected unqualified-id before ‘else’
    lab05.cpp:61: error: expected declaration before ‘}’ token

    Anyone care to point and laugh at what obvious mistake I'm making?
    It's supposed to read

    This program interactively reads two quiz
    scores and prints the maximum.

    Entering function GetScore
    Entering function RangeError
    You entered an invalid score.
    Scores must be in the range 0-800 (inclusive).
    Please try again.





    Here is the source:

    Code:
    
    /*
        LAB05.cpp. This program reads two quiz scores
        (between 0 and 800) and prints the maximum
    */ 
    
    #include <iostream>
    using namespace std ;
    
    /* ================================== */
    /* FUNCTION DECLARATIONS (PROTOTYPES) */
    /* ================================== */
    
    void PrintInfo(void);
           /* This function prints information that tells 
              what the program does. */ 
    
    int GetScore(void);
           /* Prompt for a score (an int), read it & return it. */
    
    bool RangeError(int score);
           /* Return true if score is out of range,
              else return false.  
              The range is 0-800, inclusive. */
    
    int maximum(int x, int y); 
           /* Return the maximum of x and y */ 
    
    /* ================================== */
    /* ================================== */
    
    int main(void)
    {
       int score1,         // score #1 
           score2;         // score #2 
       
       // Call function PrintInfo.
        PrintInfo();
       //  Call function GetScore, to obtain a value for score1.
       score1 = GetScore(); 
       //  IF score1 is out of range, print an error message.
        if (RangeError(score1));
           cout << "You entered an invalid score.\nScores must be in the range 0-800 (inclusive).\nPlease try again.\n";
          
       //   ELSE 
        else
       //         Call GetScore a second time, to obtain a value for score2.
        { 
        score2 = GetScore();
       //         IF score2 is out of range, print an error message.
            if (RangeError(score2));
              cout << "You entered an invalid score.\nScores must be in the range 0-800 (inclusive).\nPlease try again.\n";   
        //         ELSE, using a call to function maximum within a cout
       //         statement, print the maximum score.
              else  
                  cout << "The maximum of the two scores is: " << maximum(score1,score2) << endl;
         
        }    
       return 0;
    
    }
    /* ================================== */
    /*       FUNCTION DEFINITIONS         */
    /* ================================== */
    
    
    /* ================================== */
    void PrintInfo(void)
    {
       cout << endl ; 
       cout << "This program interactively reads two quiz";
       cout << endl ; 
       cout << "scores and prints the maximum.";
       cout << endl ; 
       cout << endl ; 
    }
    /* ================================== */
    
    
    /* ================================== */
    int GetScore(void)
    {
       /* stub for GetScore  */
        cout << "Entering function GetScore" << endl ;
        return 950 ; 
    }
    /* ================================== */
    
    
    /* ================================== */
    bool RangeError(int score) 
    {
       /* stub for RangeError */
        cout << "Entering function RangeError" << endl ;
    
        return true ;
    }
    /* ================================== */
    
    
    /* ================================== */
    int maximum(int x, int y)
    {
       /* stub for maximum */
        cout << "Entering function maximum" << endl ;
        return x ; 
    }
    /* ================================== */
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    The if syntax is
    Code:
    if (expression) {
      // code for true
    } else {
     // code for false
    }

    Comment

    Working...