Im new to c++ and this is our first assignment. I dont even know where to start. Help!

Your task is to write a main program which asks the user for an error value and then calls a function CalculatePi (error) which returns an approximate value of π.

The function CalculatePi should use a loop to calculate the above series (*). It should keep two values, currentApproximation and nextApproximation. Initially currentApproximation = 4. The loop should keep adding and subtracting terms until the difference between currentApproximation and nextApproximation is less than error. It should then return currentApproximation.

Fbody commented: I was going to let it slide, but you double-posted it. :( -1

>> I dont even know where to start.

Start by writing a main function that asks the user for input, the passes that value to the function and have the function just return that value. Then print it out in main.

After that works, start writing the real function. Before you do that, put the coding aside and go through the algorithm step by step with pencil, paper, and calculator. When you understand the algorithm, read the spec several times, then implement the function and test.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.