![]() |
|
#1
|
|||
|
|||
Help with program using a loopOk well I'm trying to make a program that uses the pi formula and outputs 3 different answers. The formula is p = 4*(1 - (1/2i-1) + (1/2i+1). The 3 answers I need to output are when i = 100, 1000, and 100000. I need to start with i = 2 and each time through the loop another 2 gets added to i and will only output when it is at the 3 numbers; 100, 1000, and 100000. This is what I currently have and it does not work, I think I am way off with my whole code so any help would be great.
// Author : // Date : // Assignment : // Compiler : // Command line : // Collaborators : #include <iostream> using namespace std; int main(){ // Variable declarations double pione; double pitwo; double pithree; int i = 2; // Figure out cost of tuition for child do{ if (i == 100); if (i == 1000); if (i == 100000); i += 2; } while (i <= 100000){ pione = 4 *(1-(1/(2i-1) + (1/(2i + 1); pitwo = 4 *(1-1/(2i-1) + (1/(2i + 1); pithree = 4 *(1 - (1/(2i-1) + (1/(2i+1); } //tell user how much pi equals when i is 100, 1000, and 100000 cout << " When i=100 pi = " << pione << endl; cout << " When i=1000 pi = " << pitwo << endl; cout << " When i=100000 pi = " << pithree << endl; return 0; } |
|||
|
#2
|
|||
|
|||
Re: Help with program using a loopYour code is "messed up" and you definitely need to read the guidelines.
CPP / C++ / C Code:
...will at least compile, but I think that you need to seriously look at your calculations, as I doubt that it is what you want from the calculations. :davis: |
Recent GIDBlog
Not selected for officer school by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Two-Tier data dissemination code installation problem | nidhibansal1984 | Computer Software Forum - Linux | 6 | 16-Sep-2007 10:13 |
| Ineffective "if then" loop on my first program | ftmthy412 | C++ Forum | 4 | 12-Sep-2007 09:17 |
| malloc/free usage, and general good programming behavior | lavaka | C Programming Language | 7 | 14-Jun-2007 19:50 |
| Text-Based Roulette Game | mfm1983 | C++ Forum | 5 | 29-Nov-2006 12:20 |
| Total newbie to programming C! Need help... | majortom | C Programming Language | 2 | 17-Nov-2005 09:52 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The