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
harmonic , geometric, arithmetic program
Collapse
X
-
#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 exactlyComment
-
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
Comment