I have a program that has to calculate the area of a rectangle or a circle. It works well but it does not print me the output as I want it.
If I input this for example:
2
rectangle 10 2.5
circle 100
My program outputs this (showing input with {} so you can see undesired output location:
{2
rectangle 10 2.5
circle 100}25.000000
31415.926536
First of all, why does it cout the area of the first case (rectangle) after inputting the second case? Basically, I am meaning this "circle 10025.000000"
Why do I have to press enter after entering the input to get the SECOND AREA while the FIRST AREA it is calculated and printed after I copy paste the input?
Your code works fine for me. Note I used the g++ compiler:
[StudentOfJack@testing02 fun]$ g++ --version
g++ (GCC) 6.2.1 20160916 (Red Hat 6.2.1-2)
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[StudentOfJack@testing02 fun]$ g++ -o cout-formatting.exe cout-formatting.cpp
[StudentOfJack@testing02 fun]$ ./cout-formatting.exe
2
rectangle 10 2.5
25.000000
circle 100
31415.926536
[StudentOfJack@testing02 fun]$
There may be some differences though with how the <istream> and <ostream> libraries are implemented on your platform. Do you know what IDE or compiler you're using?