Search code examples
c++spacingexit-code

How to space at end of program c++


"MATH IS FUN LETS..

A.  CALCULATE THE AREA OF A CIRCLE
B.  CALCULATE THE AREA OF A TRIANGLE
C.  CALCULATE THE VOLUME OF A CUBE

Enter A, B, C 
A

What is the radius?

5

Area of circle is:  78.5397Program ended with exit code: 0"

!(https://i.sstatic.net/vEK3o.jpg) The link to the code above.

I am using xcode to write this, how do i get that "Program ended with exit code: 0" to bump down to the next line?


Solution

  • If you are using streaming operators:

    std::cout << "Area of circle is: " << circle_area << std::endl;
    

    std::endl outputs a newline and flushes the stream (outputs the buffer).
    If you don't want to flush (if the line is part of lots of output where not flushing is faster) then use this instead: << '\n'

    If for some reason you are using printf():

    printf("Area of circle is: %f\n", circle_area);
    

    \n is a newline symbol