Copiles but doesnt run....

This is a discussion on Copiles but doesnt run.... within the C++ Programming forums, part of the General Programming Boards category; I use Microsoft Visual C++ 6.0. I start a new project WIN32 or WIN Dos, anyway I put a simple ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    69

    Angry Copiles but doesnt run....

    I use Microsoft Visual C++ 6.0. I start a new project WIN32 or WIN Dos, anyway I put a simple code copy and pasted this and it doesnt run why? no errors hmmm

    #include <iostream.h>

    int main ()
    {
    cout << "Hello World!";
    return 0;
    }


    Is this a valid code? I need somehelp

    My AIM is Musicdip

  2. #2
    Registered User
    Join Date
    May 2002
    Posts
    317
    If it compiles and links are you sure it doesn't run? Or is it runniong to fast for you to see..... Try this
    Code:
    #include <iostream.h> 
    
    int main () 
    { 
           cout << "Hello World!"; 
           cin.get();
           return 0; 
    }

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,705
    Sure, it "runs". But then it closes immediately...right?
    That's because "main()" is a function, and like other functions, will not halt unless you make it do so!!!

    Try this:

    int main ()
    {
    cout << "Hello World!";
    system("pause");
    return 0;
    }
    Code:
    #include <cmath>
    #include <complex>
    bool flip(bool value)
    {
           return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0)*(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    Try this

    Code:
    #include <iostream.h>
    #include <conio.h>
    
    int main () 
    { 
    cout << "Hello World!"; 
    getch();   //stops program from closing 
    return 0; 
    }
    C++ Rules!!!!
    ------------
    Microsoft Visual Studio .NET Enterprise

  5. #5
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    All are wrong. It will run in VC++ w/o the system, cin.get(), and other crap. He has to have this:
    Code:
    int main(int argc, char *argv[])
    instead of this:
    Code:
    int main()

  6. #6
    Registered User
    Join Date
    May 2002
    Posts
    317
    Actually, I believe it will run with all the above stated options. Lets not be mean here, its nice that you have a choice of options to choose from.

  7. #7
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Yea, traveller is right

  8. #8
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,705
    Quantrizi, actually you can call main either way. For programs not processing the command line, the abreviated version works just fine...
    Code:
    #include <cmath>
    #include <complex>
    bool flip(bool value)
    {
           return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0)*(1 << (value + 2)))
        ).real() < 0;
    }

  9. #9
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    The first code posted should work fine. Are you sure you are creating a win32 console application, and entering the code in a .cpp file? Make sure that the .cpp file is present in the current project workspace.

    The code is fine, it'll run in a dos window which will ask for input when it is finished anyway. The problem is almost certainly in the way you have set up the project.

  10. #10
    Registered User
    Join Date
    Jun 2002
    Posts
    69

    Angry

    Hmmm I tried the others given and it still didnt run or execute, but I may think i know whats wrong...

    I use Visual C++ 6.0 and when I used to write #include used to be in blue, now it doesnt change colors, which means it probably cant read it or understand it. Hmmmm, why do you think it doesnt change colors anymore, I use WIN32 and WIN Dos.

  11. #11
    Registered User
    Join Date
    Jun 2002
    Posts
    69
    OK thanks for all your help but I was write it didnt read the code, somehow I followed a tuterial and I found out I was doing something wrong. I was so happy that i made the hello world! program that I even uploaded it and can be downloaded here.

    http://saclanz.freewebsitehosting.com/hello.exe

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Re-doing a C program to run in Win2000 or XP
    By fifi in forum C Programming
    Replies: 5
    Last Post: 08-17-2007, 05:32 PM
  2. how to run an exe command in c++ and get back the results?
    By mitilkhatoon in forum C++ Programming
    Replies: 5
    Last Post: 09-21-2006, 06:00 PM
  3. calculating the mode
    By bigggame in forum C Programming
    Replies: 10
    Last Post: 06-13-2006, 03:04 AM
  4. How I can Run exe file in C++
    By palang in forum C++ Programming
    Replies: 2
    Last Post: 05-10-2006, 11:55 AM
  5. Replies: 2
    Last Post: 10-29-2002, 03:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21