: Create a hierarchy chart showing the logical components of your program. Modularize your code according to your chart using the practices learned this week. Your menu should now call individual modules to do the work of the program.
#include <iostream>
#include<string>
#include <iomanip>
using namespace std;
//int calculate();
//int compareLetters(char Answers, int questions);
int main() {
double monthlyPayment;
double interestRate;
double loanAmount;
double month = 0;
int answer_1;
double balance; //Balance due
double monthPaidInt; //Month interest paid
char ch = ‘Y’;
int choice;
cout.setf(ios::fixed); // currency format into 2 decimal points
cout.setf(ios::showpoint);
cout.precision(2);
// array holds start program input
char menu[2][100] = { “Menu: Start Process (s) ” , “Menu: Quit the Process (q) ” };
int choiNos[2] = { 1, 2, };
//char timing[2][100] = { “Time: 1:00pm”, “Time: 3:00pm” };
cout << “Welcome national Bank ” << endl;
cout << “We are please in assisting you in your banking needs” << endl;
cout << “Menu” << endl;
cout << “Want to start or do you want to quit?”
<< ” Enter ‘1’ for start, or ‘2’ to quit.” << endl;
while (true)
{
//Ask user if they want to start or quit
cin >> answer_1;
if ( answer_1 >2)
{
cout << “Menu “;
cout << ” Enter ‘1’ for start, and time n 2. quit n “;
}
else {
break;
}
}
if (answer_1 == 1) {
cout << “We are Open to start at this time ” << endl;
while (ch == ‘y’ || ch == ‘Y’) {
//user prompt for gate number
for (int i = 0; i < 2; i++) {
cout << (i + 1) << “. ” << menu[i] << endl;
}
//validate user input in a loop
while (true) {
bool valid = false;
cout << endl << “Please enter your choice number : “;
cin >> choice;
for (int i = 0; i < 2; i++) {
if (choiNos[i] == choice) {
valid = true;
break;
}
}
if (!valid) {
cout << “Invalid entery!” << endl;
continue;
}
break;
}
// input
cout << “Enter the current balance of your loan: $”;
cin >> loanAmount;
cout << “Enter the interest rate : “;
cin >> interestRate;
cout << “Enter the monthly payment : $”;
cin >> monthlyPayment;
// calculate interst rate
while (interestRate >= 1)
{
interestRate = interestRate / 100;
}
balance = loanAmount* (1 + interestRate / 12) – monthlyPayment;
//
cout << “month 1 your balance is $” << balance << endl;
while (balance > 0)
{
balance = balance * (1 + interestRate / 12) – monthlyPayment;
month = month++;
cout << ” month ” << month << “, your balance is : $” << balance << endl;
}
cout << “Press Enter to end –>” << endl;
}
system(“pause”);
}
}
Expert Answer
#include <iostream>
#include<string>
#include <iomanip>
using namespace std;
void initFormatting();
void printInterfaceMessage();
void processUserRequest();
void validateUserInput();
void calculateMonthlyBalance();
int main()
{
initFormatting();
printInterfaceMessage();
processUserRequest();
return 0;
}
void initFormatting()
{
cout.setf(ios::fixed); // currency format into 2 decimal points
cout.setf(ios::showpoint);
cout.precision(2);
}
void printInterfaceMessage()
{
cout << “Welcome national Bank ” << endl;
cout << “We are please in assisting you in your banking needs” << endl;
cout << “Menu” << endl;
cout << “Want to start or do you want to quit?”
<< ” Enter ‘1’ for start, or ‘2’ to quit.” << endl;
}
void processUserRequest()
{
int answer_1;
char ch=’y’;
// array holds start program input
char menu[2][100] = { “Menu: Start Process (s) ” , “Menu: Quit the Process (q) ” };
while (true)
{
//Ask user if they want to start or quit
cin >> answer_1;
if ( answer_1 >2)
{
cout << “Menu “;
cout << ” Enter ‘1’ for start, and time n 2. quit n “;
}
else {
break;
}
}
if (answer_1 == 1)
{
cout << “We are Open to start at this time ” << endl;
while (ch == ‘y’ || ch == ‘Y’)
{
//user prompt for gate number
for (int i = 0; i < 2; i++)
{
cout << (i + 1) << “. ” << menu[i] << endl;
}
validateUserInput();
calculateMonthlyBalance();
cout << “Press Enter to end –>” << endl;
}
system(“pause”);
}
}
void validateUserInput()
{
int choiNos[2] = { 1, 2 },choice;
//validate user input in a loop
while (true)
{
bool valid = false;
cout << endl << “Please enter your choice number : “;
cin >> choice;
for (int i = 0; i < 2; i++)
{
if (choiNos[i] == choice)
{
valid = true;
break;
}
}
if (!valid)
{
cout << “Invalid entery!” << endl;
continue;
}
break;
}
}
void calculateMonthlyBalance()
{
double monthlyPayment;
double interestRate;
double loanAmount;
double month = 0;
double balance; //Balance due
// input
cout << “Enter the current balance of your loan: $”;
cin >> loanAmount;
cout << “Enter the interest rate : “;
cin >> interestRate;
cout << “Enter the monthly payment : $”;
cin >> monthlyPayment;
// calculate interst rate
while (interestRate >= 1)
{
interestRate = interestRate / 100;
}
balance = loanAmount* (1 + interestRate / 12) – monthlyPayment;
cout << “month 1 your balance is $” << balance << endl;
while (balance > 0)
{
balance = balance * (1 + interestRate / 12) – monthlyPayment;
month = month++;
cout << ” month ” << month << “, your balance is : $” << balance << endl;
}
}