harmonic , geometric, arithmetic program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cNoob
    New Member
    • Nov 2006
    • 4

    harmonic , geometric, arithmetic program

    How do I write a program using the harm,geo,arith formula but requires user input?? I know I cin>> but its suppose to accept user input including all numbers up to 900. How would I write that formula?? ( count / ((1/1)+(1/2)+(1/3)............. ........) I would have to keep going forever?? I am using a while loop ... Please help?? anyone :) Thank you
  • emaghero
    New Member
    • Oct 2006
    • 85

    #2
    What exactly do you want the program to do?

    Comment

    • tnt84
      New Member
      • Nov 2006
      • 4

      #3
      #include<iostre am>
      using namespace std;
      int main()
      {

      double result=0,top,be low,i;
      cout<<"enter 2 numbers:";
      cin>>top>>below ;
      for(i=1;i<=belo w;i++)
      {
      result+=(top/i);
      }
      cout<<"result=" <<result;
      return 0;
      }


      I wrote a program like this I don't know if this is your wish but you should explain what you want exactly

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        If you're just supposed to accept all numbers up to and including 900, but through user input, it sounds like you want

        Code:
        // while statement that keep input between 1 and 900
        while ((inputNum > 900) || (inputNum < 1)) {    
         cin >> inputNum;
        }

        Comment

        Working...