473,545 Members | 2,085 Online
Bytes | Software Development & Data Engineering Community
+ 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 1211
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
2549
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 it makes however I would like the entire script to loop 34 times and on each of those 30 loops also write the product and the price (only) onto the...
0
1413
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 xml.load(Server.MapPath("ProjectTEST.xml") Dim sDate(200,100
3
2657
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 value of y (works well). create table test (a integer) @ create table debug1 (a integer) @ create trigger test_1 after insert on test...
6
11059
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
7577
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 looping function the window becomes unmovable and cannot close under its own direction (the upper right "close 'X'") My first attempt to solve...
32
2559
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 memories are of but I think I just said loop somewhere inside the loop and it immediately jumped back to the start of the loop and began again. I can't...
16
3500
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 instructions which can sure be optimized away is the check for the break condition, at least within the time where it is known that the loop will not...
3
33336
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 code is here: foreach ( string propertyName in ht.Keys ) { this.setProperty( propertyName, ht );
8
6466
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 using a code loop and an INSERT INTO query. About 800,000 records of raw text. Later, I can then loop through and parse these 800,000 strings into...
4
6818
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 System.IO.FileSystemEventArgs) Dim strFilename As String = "c:\web\example.mdb"
0
7401
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7656
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7808
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7423
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7757
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
4945
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3450
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1884
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.