473,473 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Loop question help?

1 New Member
Hello, I'm very new to C++ and am taking an intro course at the moment. I am to write a program which would keep track of a number of songs and their lengths. When i Compile my program I get the error saying:
line 72: Error: "}" expected instead of EOF. (last line of code, no matter what it may be)
The code I have is:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream.h>
  2. #include <iomanip.h>
  3. #include <math.h>
  4. using namespace std;
  5.  
  6. void PrintTime ( int number, int finalmin, int finalsec );
  7. void PrintSong ( int number, int secs, int minutes );
  8.  
  9. int main ()
  10. {
  11.         int number;
  12.         int minute;
  13.         int minutes;
  14.         int sec;
  15.         int secs;
  16.         int finalmin;
  17.         int finalsec;
  18.  
  19.         minutes = 0;
  20.         secs = 0;
  21.         cout << "Enter track number: " << endl;
  22.        cin >> number;
  23.  
  24.         if (number <= 0)
  25.         {
  26.                 cout << "Number should be positive. Exiting." << endl;
  27.                 return 1;
  28.         }
  29.  
  30.         while (number >= 0)
  31.         {
  32.  
  33.                 if (number > 0)
  34.                 {
  35.                         cout <<
  36.     "Enter the length of song, first minutes and then seconds" << endl << endl;
  37.                         cout << "Minutes: " << endl;
  38.                         cin >> minute;
  39.                         cout << "Seconds: " << endl;
  40.                         cin >> sec;
  41.                         PrintSong ( number, minutes, secs );
  42.                         finalmin = (minutes + minute);
  43.                         finalsec = (secs + sec);
  44.                 }
  45.                 else
  46.                 {
  47.                 cout << "Invalid number. exiting.";
  48.                         return 1;
  49.                         return 1;
  50.                 }
  51.         return 0;
  52. }
  53. void PrintTime ( int number, int finalmin, int finalsec );
  54. {
  55.     cout << "There is a total of "
  56.          << finalmin << " minute, and "
  57.          << finalsec << " seconds." << "./n";
  58. }
  59.  
  60. void PrintSong ( int number, int minutes, int secs );
  61. {
  62. cout << "Track number " << number << " is " << minutes << " minutes and "
  63.  << secs << " seconds long." << "./n";
  64. }
  65.  

I'm not sure if the code is right, but I have been trying to get rid of that one error for hours and no matter what I do it gives the same error.
Any help is appreciated! thanks
Oct 15 '08 #1
3 1206
boxfish
469 Recognized Expert Contributor
You are missing the closing brace on your while loop. The compiler didn't count enough closing braces to match the number of opening braces, so it was expecting another before the End Of File.
By the way, when you post code, please put [CODE] before it and [/CODE] after it so it shows up in a box and the indentation isn't wrecked. Thanks.
Hope this helps.
Oct 15 '08 #2
newb16
687 Contributor
And btw
void PrintTime ( int number, int finalmin, int finalsec );
{
...

there should be no semicolon at the end of the line in your context.
Oct 16 '08 #3
Banfa
9,065 Recognized Expert Moderator Expert
line 72: Error: "}" expected instead of EOF
Read the error message, it tells you exactly what the problem is. Unfortunately with this type of problem it can not really tell until the end of the line so it does not give the line number.

Rigorously using a coding standard for the layout (indenting and brace position) of your code should help you spot this sort of error.
Oct 16 '08 #4

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

Similar topics

0
by: Kingdom | last post by:
I Need some serious help here. strugling novis with ASP and javascript any help would be greatly appreciated The script below does exactly what I want it to do for each product on the two passes...
0
by: Tim::.. | last post by:
Hi can someone please give me some help with this little problem I am having with the following loop ...:: CODE ::. < 'Load XM set xml = Server.CreateObject("Microsoft.XMLDOM" xml.async = fals...
3
by: Gustavo Randich | last post by:
The following seems to be a bug. The execution returns rows 1,2. It should return 1,1. In fact, if I run the code within a stored procedure alone (not in a trigger), the loop doesn't overwrite the...
6
by: Shill | last post by:
I have several questions. In C, AFAIU, a for loop is just syntactic sugar for a while loop. for (i1; i2; i3) i4; is equivalent to i1 while (i2) {
8
by: Shamrokk | last post by:
My application has a loop that needs to run every 2 seconds or so. To acomplish this I used... "Thread.Sleep(2000);" When I run the program it runs fine. Once I press the button that starts the...
32
by: cj | last post by:
When I'm inside a do while loop sometimes it's necessary to jump out of the loop using exit do. I'm also used to being able to jump back and begin the loop again. Not sure which language my...
16
by: Claudio Grondi | last post by:
Sometimes it is known in advance, that the time spent in a loop will be in order of minutes or even hours, so it makes sense to optimize each element in the loop to make it run faster. One of...
3
by: Akira | last post by:
I noticed that using foreach is much slower than using for-loop, so I want to change our current code from foreach to for-loop. But I can't figure out how. Could someone help me please? Current...
8
by: SaltyBoat | last post by:
Needing to import and parse data from a large PDF file into an Access 2002 table: I start by converted the PDF file to a html file. Then I read this html text file, line by line, into a table...
4
by: joaotsetsemoita | last post by:
hello everyone. Im trying to time out a loot after a certain time. Probably 5 to 10 minutes. I have the following function Private Sub processFileCreation(ByVal source As Object, ByVal e As...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.