Menu

Newbie help

speed996
2007-08-25
2012-09-26
  • speed996

    speed996 - 2007-08-25

    I am a super beginner at C++ trying to learn on my own and I can't get the viewing window to come up when my program starts.

    1)I am using Windows XP, Dev-C++ 4.9.9.2

    2)My basic program is:

    include <iostream>

    include <ctime>

    include <cstdlib>

    using namespace std;

    int main()
    {
    srand((unsigned)time(0));
    int random_integer;
    int lowest=1, highest=60;
    int range=(highest-lowest)+1;
    for(int index=0; index<20; index++){
    random_integer = lowest+int(range*rand()/(RAND_MAX + 1.0));
    cout << random_integer << endl;
    }
    }

    3)My compiler log states:

    Compiler: Default compiler
    Executing g++.exe...
    g++.exe "C:\Documents and Settings\Nicole Gunton\My Documents\C++ files\Random Numbers.cpp" -o "C:\Documents and Settings\Nicole Gunton\My Documents\C++ files\Random Numbers.exe" -g3 -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" -g3
    Execution terminated
    Compilation aborted by user

    How can I get the screen to pop up and display the random number?

    I know this is something very simple I am doing wrong but can't find anything in the help menu's or my C++ for Dummies. Can anyone help?

     
    • ZickNesZ

      ZickNesZ - 2007-08-25

      Put system("PAUSE"); in the end of the code.

      Example:

      include <iostream>

      include <ctime>

      include <cstdlib>

      using namespace std;

      int main()
      {
      srand((unsigned)time(0));
      int random_integer;
      int lowest=1, highest=60;
      int range=(highest-lowest)+1;
      for(int index=0; index<20; index++){
      random_integer = lowest+int(range*rand()/(RAND_MAX + 1.0));
      cout << random_integer << endl;
      }
      system("PAUSE");
      }

       
    • Wayne Keen

      Wayne Keen - 2007-08-25

      You did post your Basic 3, which implies you have read at least some of the "Please Read" thread.

      Keep reading, you will probably find your exact question is already answered there.

      In addition, please note that it is a VERY bad idea to put your code in a path with spaces in it, and boy, your path had spaces in it.

      C:\Documents and Settings\Nicole Gunton\My Documents\C++ files\Random Numbers.cpp

      (The please read thread talks about that too)

      Wayne

       
      • Wayne Keen

        Wayne Keen - 2007-08-25

        Good work in starting your first question with your Basic 3 by the way,
        that puts you in the top 99% of the new user posters. Keep it up. :)

        Wayne

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.