- #1
nodek
- 4
- 0
Hi ! I`m trying to write a program which will calculate the sum:
[tex]x+(x+x^{2})+(x+x^{2}+x{3})+...[/tex]
Hi ! I`m trying to write a program which will calculate the sum:
[tex]x+(x+x^{2})+(x+x^{2}+x{3})+...[/tex]
I want the user to type in number of terms [tex]n[/tex], as well as a value of x. Here is my attempt:
#include <iostream>
#include <string>
#include <cmath>
using namespace std;int main() {
int n, x, sum=0 ;
cout<<"Enter the value for x: "<<endl;
cin>>x;
cout<<"Enter the number of terms : " <<endl;
cin>>n;
for( int i =1; 1<=n; i++) {
for (int j=1; j<=i; j++)
{
sum+=pow(x, i);
}
}
cout<<"The sum is"<<sum<<endl;
return 0;
cin.get();
cin.get();
}Is it a good way of doing that? One of mistakes that I made was : "error C2668: 'pow' : ambiguous call to overloaded function". What should I do about it?
Regards
Nodek
[tex]x+(x+x^{2})+(x+x^{2}+x{3})+...[/tex]
Homework Statement
Hi ! I`m trying to write a program which will calculate the sum:
[tex]x+(x+x^{2})+(x+x^{2}+x{3})+...[/tex]
I want the user to type in number of terms [tex]n[/tex], as well as a value of x. Here is my attempt:
#include <iostream>
#include <string>
#include <cmath>
using namespace std;int main() {
int n, x, sum=0 ;
cout<<"Enter the value for x: "<<endl;
cin>>x;
cout<<"Enter the number of terms : " <<endl;
cin>>n;
for( int i =1; 1<=n; i++) {
for (int j=1; j<=i; j++)
{
sum+=pow(x, i);
}
}
cout<<"The sum is"<<sum<<endl;
return 0;
cin.get();
cin.get();
}Is it a good way of doing that? One of mistakes that I made was : "error C2668: 'pow' : ambiguous call to overloaded function". What should I do about it?
Regards
Nodek