1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include <iostream>
#include <cmath>
using namespace std;
double SigmaFunction(double n, double x, double a, double b, double c, double i) {
double sum;
sum = pow(((a * x) - (i * b)), c);
return sum;
}
int main() {
double n, x, a, b, c;
double sum = 0.0;
//int i = 0;
char userInput;
do {
cout << "This program will calculate the sum (ax - ib)^c, where i goes from 1 to n." << endl << "Enter the values for n, x, a, b, and c separated by spaces then press Enter." << endl;
cin >> n >> x >> a >> b >> c;
// for (i = 0; i <= n; i++) {
// sum = pow(((a * x) - (i * b)), c);
// sum += i;
// }
cout << "The sum of (" << a << "*" << x << " - i*" << b << ")^" << c << " where i goes from 1 to " << n << " is " << sum << endl;
cout << endl << "Would you like to do another calculation (Y/N)?";
cin >> userInput;
cout << endl;
} while (userInput == 'Y');
system("pause");
return 0;
}
|