#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;
}
}
}
Wednesday, June 20, 2018
Friday, June 1, 2018
Total Grade Using Your Own Inputs
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector <double> data;
double input, input2;
double total = 0, total2 = 0;
cout << "\aEnter your score for each quiz, tests and/or homework (enter 0 to end): " << endl;
do{
cin >> input;
data.push_back (input);
total += input;
} while (input != 0); // once input is 0, loop ends
cout << "\aEnter max score for each quiz, tests and/or homework (enter 0 to end): " << endl;
do{
cin >> input2;
data.push_back (input2);
total2 += input2;
} while (input2 != 0);
data.pop_back(); // prevents counting 0, removes 1 array
// since both do loops uses data, the pop_back applies to both. If you want to use a different pop_back
// then you will need to change the variable, in this case: data
// int dataSize = int(data.size());
/* if and else to prevent dividing by 0 */
if (total2 == 0)
cout << "Undefined!" << endl;
else
cout << "Your grade is: " << (total/total2)*100 << "%" << endl;
}
#include <vector>
using namespace std;
int main()
{
vector <double> data;
double input, input2;
double total = 0, total2 = 0;
cout << "\aEnter your score for each quiz, tests and/or homework (enter 0 to end): " << endl;
do{
cin >> input;
data.push_back (input);
total += input;
} while (input != 0); // once input is 0, loop ends
cout << "\aEnter max score for each quiz, tests and/or homework (enter 0 to end): " << endl;
do{
cin >> input2;
data.push_back (input2);
total2 += input2;
} while (input2 != 0);
data.pop_back(); // prevents counting 0, removes 1 array
// since both do loops uses data, the pop_back applies to both. If you want to use a different pop_back
// then you will need to change the variable, in this case: data
// int dataSize = int(data.size());
/* if and else to prevent dividing by 0 */
if (total2 == 0)
cout << "Undefined!" << endl;
else
cout << "Your grade is: " << (total/total2)*100 << "%" << endl;
}
Subscribe to:
Posts (Atom)