#include <iostream>
#include <math.h>
using namespace std;
int main()
{
double i, N, factor;
while (i > 0)
{
cout << "Option 1: (1+i)^N" << endl;
cout << "Option 2: 1 / (1+i)^N" << endl;
cout << "Option 3: ((1+i)^N-1)/i" << endl;
cout << "Option 4: ((1+i)^N-1) / (i(1+i))^N" << endl;
cout << "Option 5: i / ((1+i)^N-1" << endl;
cout << "Option 6: (i(1+i)^N) / ((1+i)^N-1" << endl;
cout << "Choose from 1 to 6 (or -1 to end program):\n";
cin >> i;
if (i == 1)
{
cout << "Enter i: " << endl;
cin >> i;
cout << "Enter N: " << endl;
cin >> N;
factor = pow((1+i), N);
cout << "Answer for option 1 is: " << factor << endl;
}
else if (i == 2)
{
cout << "Enter i: " << endl;
cin >> i;
cout << "Enter N: " << endl;
cin >> N;
factor = 1 / pow((1+i), N);
cout << "Answer for option 2 is: " << factor << endl;
}
else if (i == 3)
{
cout << "Enter i: " << endl;
cin >> i;
cout << "Enter N: " << endl;
cin >> N;
factor = pow((1+i), N) / i;
cout << "Answer for option 3 is: " << factor << endl;
}
else if (i == 4)
{
cout << "Enter i: " << endl;
cin >> i;
cout << "Enter N: " << endl;
cin >> N;
factor = pow((1+i), N);
cout << "Answer for option 4 is: " << (factor - 1) / (i*factor) << endl;
}
else if (i == 5)
{
cout << "Enter i: " << endl;
cin >> i;
cout << "Enter N: " << endl;
cin >> N;
factor = pow((1+i), N);
cout << "Answer for option 5 is: " << i/(factor - 1) << endl;
}
else if (i == 6)
{
cout << "Enter i: " << endl;
cin >> i;
cout << "Enter N: " << endl;
cin >> N;
factor = pow((1+i), N);
cout << "Answer for option 6 is: " << (i*factor) / (factor - 1) << endl;
}
else if (i > 6)
{
cout << "Incorrect option entered. Enter a new option number!" << endl;
}
if (i == -1)
{
return 0;
}
}
}
No comments:
Post a Comment