Home › Forums › C Programming › beginner help in counting
- This topic has 0 replies, 1 voice, and was last updated 17 years, 2 months ago by yamna midhat.
Viewing 0 reply threads
- AuthorPosts
- October 6, 2007 at 11:18 am #2014yamna midhatParticipant
I am a beginner that barely has a clue. This is my first post here. I am trying to loop a count so that it increases based off input. (i.e. if you entered 500 terms and wanted to increase the steps by 100 the output would be 100, 200, 300, 400, 500.) I am really lost and don’t quite even know where I am lost. I have tried to use the debugger but I am not understanding the equation to even understand the debugger. Any help would be appreciated. below is what I have done.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970#include <iostream><br />#include <iomanip><br />#include <cmath><br />using namespace std;<br />void printMessage(string);<br />int returnNumber(string);<br />int main()<br />{<br />char again;<br />int termspi,<br />steps,<br />num;<br />int countDenominator;<br />float pi = 0.0, <br />divisor = 0.0,<br />count;<br />const double NUMERATOR = 4.0;<br />cout << " Program will approximate Pi ";<br />cout << endl << endl; <br />termspi = returnNumber ("Enter the number of terms to use: "); // functions to call terms<br />cout << endl << endl;<br />steps = returnNumber("Display Pi after every how many steps?: "); // function to call steps<br />cout << "RESULTS" << endl;<br /><br />for (count = 1.0, num = 1; num <= termspi; num++) {<br />if (num % 2 == 0) // evaluate pi and decide wether to add or subract number<br />pi -= NUMERATOR/count;<br />else<br />pi += NUMERATOR/count;<br />}<br />int i = 0; <br />for (i, steps; i <= termspi; i++)<br />{<br />i = steps + steps;<br />cout << i << endl;<br />} <br />cout << fixed << showpoint;<br />cout << steps << " PI = " << setprecision(9) << pi << endl;<br />count += 2.0;<br /><br />do<br />{<br />cout << "Enter Y to run program again" << endl;<br />cout << "(or any other key to exit)" << endl;<br />cin >> again;<br />}<br />while ((again == 'Y') || (again == 'y'));<br />return 1<br />;<br />}<br /><br />void printMessage(string msg)<br />{<br />cout << msg;<br />}<br /><br />int returnNumber(string msg)<br />{<br />int num;<br />cout << msg;<br />cin >> num;<br /><br />while (num < 1){<br />cout << "Your input is not valid !!!" << endl;<br />cout << "Please Re-enter a positive non zero number: ";<br />cin >> num;}<br />cout << endl;<br />return num;<br />}<br /></cmath></iomanip></iostream>
- AuthorPosts
Viewing 0 reply threads
- The forum ‘C Programming’ is closed to new topics and replies.