Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 16th, 2006, 4:44 PM   #1
msk420
Programmer
 
msk420's Avatar
 
Join Date: May 2006
Posts: 85
Rep Power: 3 msk420 is on a distinguished road
Whats wrong with this

Ok the first { is the problem... when I compile the code it says that main must return a integer....

#include <iostream>
#include <ctime>

using namespace std;

void main( void )
{  /* the problem is this bracket right here */
     int i, j;
     srand( (unsigned)time( NULL ) );
     /* Display 10 numbers */
     for ( i = 0; i < 10; i++)
     {
         j = rand();
         cout << j << endl;
         }
     
     system ( "PAUSE" );
     cin.get();
     return 0;
}
__________________
Code Forums
msk420 is offline   Reply With Quote
Old May 16th, 2006, 4:58 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
That's a fairly clear error message. Main is supposed to return an integer. Returning an integer when you've declared the return to be void is prolly not the slickest move you'll make today. The bracket has nada to do with it. Try "int main (...blah blah...)". Incidentally, some compilers will accept "void main (....", but that doesn't mean it's right. MSDN, bless their pea-pickin' li'l hearts, published a lot of sample code that did that, rightly or wrongly.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old May 16th, 2006, 5:01 PM   #3
msk420
Programmer
 
msk420's Avatar
 
Join Date: May 2006
Posts: 85
Rep Power: 3 msk420 is on a distinguished road
Thanks DaWei... I didn't realize that it was that simple sorry for posting a simple error...
__________________
Code Forums
msk420 is offline   Reply With Quote
Old May 16th, 2006, 5:04 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Hey, nothing wrong with simple errors. That's the kind that give us the most gray hairs. The merits of "void main" are a relatively frequent topic of discussion.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old May 16th, 2006, 5:06 PM   #5
msk420
Programmer
 
msk420's Avatar
 
Join Date: May 2006
Posts: 85
Rep Power: 3 msk420 is on a distinguished road
Ok thanks....
__________________
Code Forums
msk420 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:31 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC