Search:
Forum
Beginners
Data Types Question
Data Types Question
Aug 1, 2011 at 6:10pm UTC
Uranium238
(14)
#include <iostream>
using namespace std;
#define PI 3.14159265358979
#define NEWLINE '\n' //no idea what newline does
int main ()
{
double r=5.0;
double circle;
circle = 2*PI*r;
cout << circle;
cout << NEWLINE;
return 0;
}
When I run this code, all i get is 31.4159. My question is why don't I get 31.4159265358979. Also, what is newline? I'm not sure what it does.
Aug 1, 2011 at 6:38pm UTC
webJose
(2948)
NEWLINE adds a new line to the output. If it were a text file, NEWLINE would be the equivalent of pressing the ENTER key. But don't use NEWLINE as defined there. Use std::endl. Better.
You also don't get the entire precision because the output's precision is not set. See
http://www.cplusplus.com/reference/iostream/manipulators/setprecision/
.
Topic archived. No new replies allowed.
C++
Information
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs