![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: May 2006
Posts: 85
Rep Power: 3
![]() |
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 |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#3 |
|
Programmer
Join Date: May 2006
Posts: 85
Rep Power: 3
![]() |
Thanks DaWei... I didn't realize that it was that simple sorry for posting a simple error...
__________________
Code Forums |
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#5 |
|
Programmer
Join Date: May 2006
Posts: 85
Rep Power: 3
![]() |
Ok thanks....
__________________
Code Forums |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|