Menu

C++ question

2009-01-24
2012-09-26
  • John Strobel

    John Strobel - 2009-01-24

    I am teaching myself the basics of C++ with books and online tutorials. In C++ without fear, I am doing the small exercises about your first programs. I type them instead of copy and paste, can someone tell me what im doing wrong. I compile and run this program, after i input the number and press ENTER, it doesnt finish the program.

    include <iostream>

    using namespace std;

    int main()
    {
    double n;

    cout << "Input number and press ENTER: ";
    cin >> n;

    cout << "The square is: " << n*n;

    return 0;
    }

     
    • cpns

      cpns - 2009-01-25

      It runs to completion. When that happens the OS closes the program's window. This is perfectly normal behaviour you will have observed in other programs many times, but people are still often surprised when it occurs in their own code!

      Note; we never tire of answering this question so perhaps the answer should be removed from the "PLEASE READ BEFORE POSTING A QUESTION" thread. (Note the sarcasm).

      Clifford

       
    • Musa

      Musa - 2009-01-25

      >it doesnt finish the program.

      actually it does
      run it from th command prompt and you'll see
      and also read the "PLEASE READ BEFORE POSTING A QUESTION" thread

       

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.