[Q] HELP (Tut1) [C++]

This is a discussion on [Q] HELP (Tut1) [C++] within the C++ Programming forums, part of the General Programming Boards category; I follow exact instructions in this Tutorial I compile test.cpp. The code I compile is... Code: #include <iostream.h> int main() ...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    6

    [Q] HELP (Tut1) [C++]

    I follow exact instructions in this Tutorial

    I compile test.cpp.

    The code I compile is...

    Code:
    #include <iostream.h>
    int main()
    {
      cout<<"HEY, you, I'm alive!  Oh, and Hello World!";
      return 0;    
    }
    I compile it into a .exe and when I run it...

    It opens, for 0.5 second and then closes.

    What am I doing wrong?

    I'm running Windows XP Professional, service pack 1.
    using MS C++ to compile this

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    6
    Nevermind, Problem fixed.

    Code:
    #include <iostream.h>
    void main()
    {
    int x;
    cout << "Hi!";
    cin >> x;
    }

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    6
    Hmmm nope that justs wait for a reply then closes.

    Code:
    #include <iostream.h>			
    int main()				//Most important part of the program!
    {
      int age;				//Need a variable...
      cout<<"Please input your age: ";	//Asks for age
      cin>>age;				//The input is put in age
      if(age<100)				//If the age is less than 100
      {
         cout<<"You are pretty young!";     //Just to show it works
      }
      else if(age==100)		//I use else just to show an example 
      {
         cout<<"You are old";		//Just to show you it works...
      }
      else
      {
        cout<<"You are really old";	//Executed if no other statement is executed
      }
      return 0;
    }
    Help please, I enter my age then it closes.

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    >>void main()
    GAH! Don't use void main()!
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    30

    Lightbulb Flashes on the screen .5 sec

    from one newb to another . . . ;oD

    Code:
    // I like to start all programs like this...
    
    #include <iostream>
    #include <cstdlib>  //for the system command
    
    using namespace std;
    
    int main()
    {
      . . .
    
      system("pause");   //system pause command
      return 0;
    }
    Try that and see if it doesn't keep it on the screen for you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I need a programmer [C or C++] for free
    By carlo67 in forum Projects and Job Recruitment
    Replies: 11
    Last Post: 08-24-2007, 06:02 PM
  2. [C# COM development] output by Regasm
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 07-22-2007, 02:12 PM
  3. [C Video Tutorial Collection]
    By Chernobyl in forum C Programming
    Replies: 17
    Last Post: 04-07-2007, 02:24 AM
  4. [C colors]
    By FEAR in forum C Programming
    Replies: 1
    Last Post: 06-06-2006, 03:24 PM

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