Devin Dahlberg

C++ : Assignment Two

// This program asks for the principal, the interest rate, and the number of times the interest is compounded; then outputs the amount.
//
//
//Program from Starting Out With C++ from Control Structures through Objects (Ninth Edition) by Tony Gaddis(2018) pg. 147, Problem #18.
//
// Programmed by Devin Dahlberg, CIS 251 Student
// January 22, 2024

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
	double principal, interestRate, irAdjust, numTimes, interest, amount, before, squared;

	// Get the Principal
	cout << "What is the principal? ";
	cin >> principal;

	//Get the Interest Rate
	cout << "What is the Interest Rate? ";
	cin >> interestRate;

	//Get the number of times the interest is compounded
	cout << "How many times is the interest compounded? ";
	cin >> numTimes;

	//Finds the amount by portioning out the equation Amount = Principal * (1 + Rate / Number of Time Compounded) ^ Number of Times Compounded
	irAdjust = interestRate / 100;

	before = (1 + irAdjust / numTimes);

	squared = pow(before,numTimes);

	amount = principal * squared;

	//Find the interest
	interest = amount - principal;


	//Prints the report
	cout << setprecision(2) << fixed;
	cout << "Interest Rate:                  " << interestRate << "%\n";
	cout << setprecision(0) << fixed;
	cout << "Times Compounded:               " << numTimes << "\n";
	cout << setprecision(2) << fixed;
	cout << "Principal:                    $ " << principal << "\n";
	cout << "Interest:                     $ " << interest << "\n";
	cout << "Amount in Savings:            $ " << amount << "\n";


	return 0;
}

image