Computer Science Canada

void main() error

Author:  romantic_programmer [ Thu Dec 18, 2008 10:26 pm ]
Post subject:  void main() error

I am tring to complie my work here and i keep receiving these messages.

line file message
4 C:\Users\Jeremy\Desktop\Azuregale\Main.cpp `main' must return `int'
C:\Users\Jeremy\Desktop\Azuregale\Makefile.win [Build Error] [Main.o] Error 1

Example code below. i am running Dev C++ and within my Library.h is my #include <iostream> and my using namespace std;
Please can someone explain to me what i am doing wrong.

code:

#include "Library.h"

void main()
{
    //     Welcome Screen
   
    cout << "\n\nWelcome to AzureGale V0.0.01,\n";
    cout << "Programmed By: Jeremy Poisson\n\n";
   
}

Author:  Tony [ Thu Dec 18, 2008 11:21 pm ]
Post subject:  Re: void main() error

romantic_programmer @ Thu Dec 18, 2008 10:26 pm wrote:
`main' must return `int'

code:

void main()

void is not int

code:

int main(){
   return 0;
}

Author:  romantic_programmer [ Thu Dec 18, 2008 11:48 pm ]
Post subject:  RE:void main() error

Thank you for the advice tony, but unfortunetly every time i try to run the program it shows nothing... shouldn't it at least show the text up in my example?

Author:  wtd [ Thu Dec 18, 2008 11:49 pm ]
Post subject:  RE:void main() error

http://wiki.compsci.ca/index.php?title=Window_closes_instantly

Author:  romantic_programmer [ Thu Dec 18, 2008 11:58 pm ]
Post subject:  RE:void main() error

but i even ran it through a command shell.. shouldn't that at least stay open? well as i was reading it should but it dosn't even load anything

Author:  wtd [ Fri Dec 19, 2008 12:15 am ]
Post subject:  RE:void main() error

Post your code. Your latest code. Tell us exactly how you're trying to run it.

Author:  romantic_programmer [ Fri Dec 19, 2008 12:22 am ]
Post subject:  Re: void main() error

This is my latest code. Very simple but still

THis is the Main.cpp
code:
#include "Library.h"

int main()
{
    //     Welcome Screen
   
    cout << "\n\nWelcome to AzureGale V0.0.01,\n";
    cout << "Programmed By: Jeremy Poisson\n\n";
   
    cout << "A land that has been divided up into Kingdoms and\n is at risk of falling into a Kingdoms War. Though their has been violence\n with in the lands it seems to have gotten even more chaotic in \nrecent years. You believe you are the world last hope for global peace. \nIf not may the Gods save all who are worthy of their grace.";
    return 0;
}


This is the Library.h
code:

#include <iostream>
using namespace std;


I haven't added anymore since i couldn't get it to run.

Author:  wtd [ Fri Dec 19, 2008 12:49 am ]
Post subject:  RE:void main() error

Works fine here.

Author:  romantic_programmer [ Fri Dec 19, 2008 12:58 am ]
Post subject:  RE:void main() error

i am so confused. do you think it could just be the default DEV C++ 4.9.9.2 compiler?

Author:  DemonWasp [ Fri Dec 19, 2008 1:03 am ]
Post subject:  RE:void main() error

That should all work fine. It's worth noting that you should use "endl" instead of "\n":

cout << "Programmed By: Jeremy Poisson" << endl << endl;

If you still are having trouble, list the exact series of commands you're using to compile and run your program.

Author:  romantic_programmer [ Fri Dec 19, 2008 1:11 am ]
Post subject:  Re: void main() error

code:
#include "Library.h"

int main()
{
    //     Welcome Screen
   
    cout << "\n\nWelcome to AzureGale V0.0.01,\n";
    cout << "Programmed By: Jeremy Poisson" << endl << endl;
   
    cout << "A land that has been divided up into Kingdoms and\n is at risk of falling into a Kingdoms War. Though their has been violence\n with in the lands it seems to have gotten even more chaotic in \nrecent years. You believe you are the world last hope for global peace. \nIf not may the Gods save all who are worthy of their grace.";
   
    AzurianGates();
   
    return 0;
}


it still didn't work. I am starting to think it is the compiler or something because when i load the application even in the command prompt it shows nothing. just goes to the next line.

also i have a question about syntax what is proper \n or endl;

Author:  wtd [ Fri Dec 19, 2008 2:18 am ]
Post subject:  RE:void main() error

use endl.

Author:  romantic_programmer [ Fri Dec 19, 2008 2:27 am ]
Post subject:  RE:void main() error

And can you possible suggest a a better compiler... i am running vista home basic. if that helps

Author:  wtd [ Fri Dec 19, 2008 3:02 am ]
Post subject:  RE:void main() error

Which compiler (and version) are you using now?

Author:  romantic_programmer [ Fri Dec 19, 2008 3:07 am ]
Post subject:  RE:void main() error

Well I just Downloaded Dev - C++ 4.9.9.2

and i am using it's default compiler which i think is the mingw.

Author:  OneOffDriveByPoster [ Fri Dec 19, 2008 10:30 am ]
Post subject:  Re: RE:void main() error

wtd @ Fri Dec 19, 2008 2:18 am wrote:
use endl.
endl << endl is just bad. That should have one '\n' and one endl.

Author:  Dan [ Fri Dec 19, 2008 5:29 pm ]
Post subject:  RE:void main() error

endl != '\n'

On some OSs the line break is just '\n' such as most *nix based ones. However on windows it is "\r\n" and on some very old mac OSs it is just '\r'.

Author:  romantic_programmer [ Fri Dec 19, 2008 5:55 pm ]
Post subject:  RE:void main() error

DAN i just made a break through... I got my code to compile. Yay!

I Got rid of the DEV editor then just went back to basics...

now i am running the crimsion editor and the minGW compiler.

it took me a few attempts to compile the work but this is what i type and it works

c++ Main.cpp -o AzureGale.exe

Now i was wondering if someone could explain to me that the -o part means... i think it means output but i not sure

Author:  wtd [ Fri Dec 19, 2008 6:08 pm ]
Post subject:  RE:void main() error

Essentially, yes. It provides an output file name.

When in doubt, "gcc --help" is your friend.

Author:  OneOffDriveByPoster [ Sat Dec 20, 2008 8:24 am ]
Post subject:  Re: RE:void main() error

Dan @ Fri Dec 19, 2008 5:29 pm wrote:
endl != '\n'

On some OSs the line break is just '\n' such as most *nix based ones. However on windows it is "\r\n" and on some very old mac OSs it is just '\r'.
The '\n' when printed to a text-stream produces the correct end-of-line character sequence. The difference between using '\n' and endl is elsewhere.


: