C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-30-2005, 05:15 AM   #1
Registered User
 
Join Date: Nov 2005
Posts: 13
More digits in output, particular digits output, output in *.txt

I've started programming 1 week ago and I use win32 console for an output.

In program which calculates pi:
Code:
Code:
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
  double b=-1;
  double pi=acos(b);
  cout << pi << endl;
  
  system("PAUSE");	
  return 0;
}
The output is:
Output:
Code:
3.14159
I know that computer calculated pi with much higher precision, so how do I get, I don't know... 15 digits on the output screen?

One more related question. I'm trying to write a random number generator program, since I've noticed that the rand() function doesn't have the uniform distribution of random number values, and for that I need a function that would "cut" double variable started from some decimal value to some other decimal value. For example, if I have a double variable number pi=3.141592654... I want a new integer variable with value from 3rd to 6th digit, int a=592. How do I do that?

The final question. If I want to test relationship between many output variables it would be very usefull if program could put these values in a txt file. How do I do that? Remember (I don't know if that maters) I'm programming (or trying to ), that is, the output is in win32 console.

Thank you!

Last edited by Ene Dene; 11-30-2005 at 05:19 AM.
Ene Dene is offline   Reply With Quote
Old 11-30-2005, 05:23 AM   #2
Programmer
 
Join Date: Nov 2005
Location: Canada
Posts: 33
Do you mean PI as in PIE? Well so far it's been 100% impossible to get the exact digits for pie since the Math Professers and other researchers are still getting 3.################################### ect...

Now I'm new as well but I might be able to just give my thought. The number PI= what your trying to get may be more bytes then a double can hold. Well thats just my guess.
__________________
(Expert Visual Basic Programmer)
(Newbie C/C++ Programmer)
dimirpaw is offline   Reply With Quote
Old 11-30-2005, 06:24 AM   #3
Registered User
 
Join Date: Nov 2005
Posts: 13
Quote:
Originally Posted by dimirpaw
Do you mean PI as in PIE? Well so far it's been 100% impossible to get the exact digits for pie since the Math Professers and other researchers are still getting 3.################################### ect...

Now I'm new as well but I might be able to just give my thought. The number PI= what your trying to get may be more bytes then a double can hold. Well thats just my guess.
Of course that I didn't mean PI with infinite number of digits (as I stated by "I know that computer calculated pi with much higher PRECISION, so how do I get, I don't know... 15 digits on the output screen?"), it is transcedental, by definition it is imposible, but that was not the question.
Ene Dene is offline   Reply With Quote
Old 11-30-2005, 11:18 AM   #4
^ Read Backwards^
 
Join Date: Sep 2005
Location: Earth
Posts: 282
Code:
#include <cmath>
#include <iomanip>

....
....
	cout << setprecision (15) << pi; //or any #
.....
Enahs is offline   Reply With Quote
Old 11-30-2005, 04:44 PM   #5
Registered User
 
Join Date: Nov 2005
Posts: 13
Thanks!
Ene Dene is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Having trouble making a function do what I want. Shamino C++ Programming 9 12-07-2007 11:20 AM
Base converter libary cdonlan C++ Programming 22 05-15-2005 01:11 AM
Need help fixing bugs in data parsing program daluu C Programming 8 03-27-2003 06:02 PM
Control different DA output value! Hunterhunter A Brief History of Cprogramming.com 1 03-13-2003 12:11 PM


All times are GMT -6. The time now is 10:20 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22