Home Forums C Programming beginner help in counting

Viewing 0 reply threads
  • Author
    Posts
    • #2014
      yamna midhat
      Participant

      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. 

      #include 
      #include
      #include
      using namespace std;
          void printMessage(string);
          int returnNumber(string);
      int main()
      {
          char again;
          int termspi,
              steps,
              num;
          int countDenominator;
          float pi = 0.0,   
         divisor = 0.0,
          count;
          const double NUMERATOR = 4.0;
          cout << " Program will approximate Pi ";
          cout << endl << endl;   
          termspi = returnNumber ("Enter the number of terms to use: ");     // functions to call terms
          cout << endl << endl;
          steps = returnNumber("Display Pi after every how many steps?: ");  // function to call steps
          cout << "RESULTS" << endl;
         
          for (count = 1.0, num = 1; num <= termspi; num++) {
              if (num % 2 == 0)                  // evaluate pi and decide wether to add or subract number
                 pi -= NUMERATOR/count;
              else
                pi += NUMERATOR/count;
          }
          int i = 0;     
          for (i, steps; i <= termspi; i++)
          {
                i = steps + steps;
                cout << i <<  endl;
           }    
              cout << fixed << showpoint;
              cout << steps << " PI = " << setprecision(9) << pi << endl;
              count += 2.0;

      do
      {
              cout << "Enter Y to run program again" << endl;
              cout << "(or any other key to exit)" << endl;
              cin >> again;
      }
          while ((again == 'Y') || (again == 'y'));
          return 1
          ;
      }
       
      void printMessage(string msg)
      {
           cout << msg;
      }

      int returnNumber(string msg)
      {
           int num;
           cout << msg;
           cin >> num;
          
           while (num < 1){
               cout << "Your input is not valid !!!" << endl;
               cout << "Please Re-enter a positive non zero number: ";
               cin >> num;}
               cout << endl;
           return num;
      }

       

Viewing 0 reply threads
  • The forum ‘C Programming’ is closed to new topics and replies.