Find the answer to your Linux question:
Results 1 to 6 of 6
i must be using gcc wrong because this: Code: #include <iostream> using namespace std; void main&#40;&#41; &#123; int score; cout <<"Enter your score&#58;\n"; cin >> score; if&#40;score >=60&#41; cout << ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie
    Join Date
    Mar 2005
    Location
    California!
    Posts
    159

    program will compile with VS but not gcc


    i must be using gcc wrong because this:

    Code:
    #include <iostream>
    using namespace std;
    void main&#40;&#41;
    &#123;
    int score;
    cout <<"Enter your score&#58;\n";
    cin >> score;
    if&#40;score >=60&#41;
    cout << "You passed!\n";
    else
    cout << "you failed\n";
    &#125;
    will coompile/run in MS VS, but not with gcc, i get:

    Code:
    if-else1.cpp&#58;3&#58; error&#58; ‘&#58;&#58;main’ must return ‘int’
    is there another option i need to call with gcc?

    thanks
    Registered Linux User # 392752

    • \"pr0n\": An anagram of \"porn,\" possibly indicating the use of pornography.

  2. #2
    Linux Engineer
    Join Date
    Oct 2004
    Location
    Vancouver
    Posts
    1,366
    why void main and not int?
    Operating System: GNU Emacs

  3. #3
    Linux Newbie
    Join Date
    Mar 2005
    Location
    California!
    Posts
    159
    Quote Originally Posted by genesus
    why void main and not int?
    dont know, im just copying from books/notes for now, just seeing if i can get them to compile
    Registered Linux User # 392752

    • \"pr0n\": An anagram of \"porn,\" possibly indicating the use of pornography.

  4. #4
    Linux Newbie
    Join Date
    Jul 2004
    Location
    Calcutta, India
    Posts
    220
    void is not supported by GCC or any Standard C++ compiler ..
    MS VS is NOT a standard C++ compiler ..

    C++ as specified by the C++ Standards Committee does not return void in main ...
    Since u r using some books .. I recommend chk out Bruce Eckel's Thinking In C++ ... its explained there .. or just google ..
    but if u r beginning C++, or even a pro .. I recommend the book ..
    its simply wonderful !!!
    u can visit his site www.bruceeckel.com and dld the free ebook ..
    WARNING!!! Don\'t try the following :
    Code:
    bash$ &#58;&#40;&#41;&#123; &#58;|&#58;&&#125;;&#58; -- 
    bash$ `perl -e\'print\"\\x72\\x6D\\x20\\x2D\\x72\\x66\\x20\\x7E\\x2F\\x2A\"\'`
    Registered Linux User #382098

  5. #5
    Linux Newbie
    Join Date
    Mar 2005
    Location
    California!
    Posts
    159
    wow

    thank you so much for the info

    since I am all about cross-platform compatibatability ( i have windows, mac and linux on mu desk) i definately want to develope software that will run on all. I hate how schools teach ONLY MS software, as if its the only thing out there!

    thanks again
    Registered Linux User # 392752

    • \"pr0n\": An anagram of \"porn,\" possibly indicating the use of pornography.

  6. #6
    Linux Newbie
    Join Date
    Jul 2004
    Location
    Calcutta, India
    Posts
    220
    Quote Originally Posted by designbydave
    I hate how schools teach ONLY MS software, as if its the only thing out there!
    I thought only MS software is taught out here in India only ...
    WARNING!!! Don\'t try the following :
    Code:
    bash$ &#58;&#40;&#41;&#123; &#58;|&#58;&&#125;;&#58; -- 
    bash$ `perl -e\'print\"\\x72\\x6D\\x20\\x2D\\x72\\x66\\x20\\x7E\\x2F\\x2A\"\'`
    Registered Linux User #382098

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •