473,395 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

expected } before else

Thanks for reading this in advance

Basically I compile my script and I get this return error
Expand|Select|Wrap|Line Numbers
  1.  
  2. lab05.cpp: In function ‘int main()’:
  3. lab05.cpp:46: error: expected `}' before ‘else’
  4. lab05.cpp: At global scope:
  5. lab05.cpp:46: error: expected unqualified-id before ‘else’
  6. lab05.cpp:61: error: expected declaration before ‘}’ token
  7.  
  8.  

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:

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. /*
  4.     LAB05.cpp. This program reads two quiz scores
  5.     (between 0 and 800) and prints the maximum
  6. */ 
  7.  
  8. #include <iostream>
  9. using namespace std ;
  10.  
  11. /* ================================== */
  12. /* FUNCTION DECLARATIONS (PROTOTYPES) */
  13. /* ================================== */
  14.  
  15. void PrintInfo(void);
  16.        /* This function prints information that tells 
  17.           what the program does. */ 
  18.  
  19. int GetScore(void);
  20.        /* Prompt for a score (an int), read it & return it. */
  21.  
  22. bool RangeError(int score);
  23.        /* Return true if score is out of range,
  24.           else return false.  
  25.           The range is 0-800, inclusive. */
  26.  
  27. int maximum(int x, int y); 
  28.        /* Return the maximum of x and y */ 
  29.  
  30. /* ================================== */
  31. /* ================================== */
  32.  
  33. int main(void)
  34. {
  35.    int score1,         // score #1 
  36.        score2;         // score #2 
  37.  
  38.    // Call function PrintInfo.
  39.     PrintInfo();
  40.    //  Call function GetScore, to obtain a value for score1.
  41.    score1 = GetScore(); 
  42.    //  IF score1 is out of range, print an error message.
  43.     if (RangeError(score1));
  44.        cout << "You entered an invalid score.\nScores must be in the range 0-800 (inclusive).\nPlease try again.\n";
  45.  
  46.    //   ELSE 
  47.     else
  48.    //         Call GetScore a second time, to obtain a value for score2.
  49.     { 
  50.     score2 = GetScore();
  51.    //         IF score2 is out of range, print an error message.
  52.         if (RangeError(score2));
  53.           cout << "You entered an invalid score.\nScores must be in the range 0-800 (inclusive).\nPlease try again.\n";   
  54.     //         ELSE, using a call to function maximum within a cout
  55.    //         statement, print the maximum score.
  56.           else  
  57.               cout << "The maximum of the two scores is: " << maximum(score1,score2) << endl;
  58.  
  59.     }    
  60.    return 0;
  61.  
  62. }
  63. /* ================================== */
  64. /*       FUNCTION DEFINITIONS         */
  65. /* ================================== */
  66.  
  67.  
  68. /* ================================== */
  69. void PrintInfo(void)
  70. {
  71.    cout << endl ; 
  72.    cout << "This program interactively reads two quiz";
  73.    cout << endl ; 
  74.    cout << "scores and prints the maximum.";
  75.    cout << endl ; 
  76.    cout << endl ; 
  77. }
  78. /* ================================== */
  79.  
  80.  
  81. /* ================================== */
  82. int GetScore(void)
  83. {
  84.    /* stub for GetScore  */
  85.     cout << "Entering function GetScore" << endl ;
  86.     return 950 ; 
  87. }
  88. /* ================================== */
  89.  
  90.  
  91. /* ================================== */
  92. bool RangeError(int score) 
  93. {
  94.    /* stub for RangeError */
  95.     cout << "Entering function RangeError" << endl ;
  96.  
  97.     return true ;
  98. }
  99. /* ================================== */
  100.  
  101.  
  102. /* ================================== */
  103. int maximum(int x, int y)
  104. {
  105.    /* stub for maximum */
  106.     cout << "Entering function maximum" << endl ;
  107.     return x ; 
  108. }
  109. /* ================================== */
  110.  
Oct 19 '11 #1
1 5803
Rabbit
12,516 Expert Mod 8TB
The if syntax is
Expand|Select|Wrap|Line Numbers
  1. if (expression) {
  2.   // code for true
  3. } else {
  4.  // code for false
  5. }
Oct 19 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

27
by: Ron Adam | last post by:
There seems to be a fair amount of discussion concerning flow control enhancements lately. with, do and dowhile, case, etc... So here's my flow control suggestion. ;-) It occurred to me (a...
3
by: Patrice | last post by:
Hi, I need to do multi-conditional statements like below, but this error is displayed : Expected 'End' /myFilepath, line x else response.write(arrCorpo(sparam,sdiv)) end if I don't...
4
by: Bill | last post by:
I call a function in my .js file like this: onClick="location.href='blank.html' + generateSearchStringFromForm('section')" where section is the name of my form. The function is defined as...
2
by: Chuck Martin | last post by:
I am having a most frustrating problem that references, web searches, and other resources are no help so far in solving. Basically, I'm trying to design a pop-up window to be called with a funciton...
2
by: kumar mcmillan | last post by:
hi. I am using a pseudo "pivot table" SQL query to generate a report but I am totally stumped on why the COUNT() function isn't getting me the expected results and was wondering if anyone has some...
11
by: westplastic | last post by:
This one is driving me insane. The script works perfect on Firefox, but Internet Explorer keeps complaining about "Error Object Expected" and stuff like that. I've run it through Firefox's Java...
1
nmm32
by: nmm32 | last post by:
I am trying to use Ajax with JSP to populate a 2nd drop down list based on the chosen option of the first one. I am getting the error "Object Expected" on the line 13-14 of the HTML: <script...
2
by: audiokarate | last post by:
I have like atleast 15 errors that say class, interface, or enum expected and I have no idea what that means. Can someone tell me what it is and how I might be able to fix it? Thank you. - Manny...
1
by: finizaini | last post by:
I'm receiving an "Object Expected" Error (Line:309, Char:0). I'm confused as to what is happening.Also, I can't run this code using other browser such as Fire Fox. Thispage only can view using IE....
9
by: erictheone | last post by:
Ok so what I'm trying to do is create a trans location cipher. For those among us that don't know alot about cryptography it is a method for jumbling up letters to disguise linguistic...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.