c++ Syntax (Toggle Plain Text) - /*
- Write the program as a procedural C++ program. Allow the user to input
- the amount of a mortgage and then select from a menu of mortgage loans:
-
- 7 year at 5.35%
- 15 year at 5.5%
- 30 year at 5.75%
-
- Use an array for the different loans. Display the mortgage payment amount.
- Then, list the loan balance and interest paid for each payment over the term
- of the loan. On longer-term loans, the list will scroll off the screen.
- Do not allow the list to scroll off the screen, but rather display a partial
- list and then allow the user to continue the list. Allow the user to loop back
- and enter new data or quit. Insert comments in the program to document the
- program.
- */
-
- #include <math.h> // Math Constant
- #include <cstdlib> // Standard Library
- #include <iostream> // Defines facilities for basic I/O operations
- using namespace std; // Namespace standard library
-
- int main(int argc, char *argv[]) // Main, argc and *argv give the number and value of the program's command-line arguments
- {
- cout << " " << endl; // Empty line before assignment title
- cout << " ///////////////////////////////////////////////////////////////////////// " << endl;
- cout << " // // " << endl;
- cout << " // Calculate and display the mortgage payment amount using the amount // " << endl;
- cout << " // of the mortgage, the term of the mortgage, and the interest rate // " << endl;
- cout << " // of the mortgage. The user will enter the amount of the mortgage // " << endl;
- cout << " // and will select from a menu the amount of years and interest rate. // " << endl;
- cout << " // The mortgage payment will display and the ammortization table will // " << endl;
- cout << " // display the loan balance and interest paid. The user will be // " << endl;
- cout << " // allowed to either continue the ammortization table, enter new // " << endl;
- cout << " // loan data or quit the program altogether. // " << endl;
- cout << " // // " << endl;
- cout << " ///////////////////////////////////////////////////////////////////////// " << endl;
- cout << " " << endl << endl << endl << endl << endl << endl;
-
- double loanAmount, // Amount of the Loan
- monthlyPayment, // Monthly Payment of the Loan
- loanBalance, // Balance of the Loan
- intPaid, // Interest Paid on the Loan
- amountPaid, // Amount Paid on the Loan
- intRate[3]={5.25,
- 5.50,
- 5.75}; // Interest Rate of the Loan
-
- int numPayments, // Number of Payments
- paymentCounter,
- dividelist = 0, // Display partial list
- length[3]={7, 15, 30}; // Length of the Loan
-
- char listmore;
- char quit; // Prompt user to quit
- quit = 'C'; // Quit variable
-
- while (quit != 'Q' && quit != 'q')
- {
- cout << "\t Enter Loan Amount (*NUMBERS ONLY*): ";
- cin >> loanAmount;
- cout << "\t Select Line Number for Length of Loan and Interest Rate " << endl;
- cout << "\t 1. 7 Years at 5.35% " << endl;
- cout << "\t 2. 15 Years at 5.50% " << endl;
- cout << "\t 3. 30 Years at 5.75% " << endl;
- cout << "\t Enter Line Number Here: ";
-
- int choice;
- cin >> choice;
- cout << endl;
-
- int i;
- for (i = 0; i < 1; i++)
- switch (choice)
- {
- case 1:
- cout << "\t You Selected 7 Years at 5.35%" << endl;
- break;
- case 2:
- cout << "\t You Selected 15 Years at 5.50%" << endl;
- break;
- case 3:
- cout << "\t You Selected 30 Years at 5.75%" << endl;
- break;
- default:
- cout << "\t Invalid Line Number" << endl;
- // Still having minor issues with invalid number
- if (choice != 1,2,3)
- {
- cout << "\t Enter Line Number Here: ";
- int choice;
- cin >> choice;
- cout << endl;
- if (choice != 1,2,3)
- {
- cout << "\t You cannot follow directions. " << endl;
- case 9:
- cout << "\t Program will now END " << endl;
- break;
- }
- }
- }
-
- cout << endl;
-
- monthlyPayment = loanAmount * (intRate[choice] / 1200) /
- (1 - pow(1 + (intRate[choice] / 1200), - 1 * (length[choice] * 12)));
-
- cout << "\t Monthly Payments: $" << monthlyPayment << endl << endl;
- numPayments = length[choice] * 12;
- dividelist = 0;
-
- for (paymentCounter = 1; paymentCounter <= numPayments; ++paymentCounter)
- {
- // Math Formula for intPaid to set up value for amountPaid
- intPaid = loanAmount * (intRate[choice] / 1200);
- amountPaid = monthlyPayment - intPaid;
- loanBalance = loanAmount - amountPaid;
-
- if (loanBalance < 0)loanBalance = 0;
- loanAmount = loanBalance;
-
- if (dividelist == 0)
- {
- cout << "\t\tLoan Balance" << "\t\tInterest Paid" << endl;
- cout << "\t\t____________" << "\t\t_____________" << endl << endl;
- }
-
- cout << "\t\t$" << loanBalance << "\t\t\t$" << intPaid << endl;
- ++dividelist;
-
- // User to Continue, enter New Data or Quit
- if (dividelist == 12)
- {
- cout << endl << endl;
- cout << "\tEnter 'C' to Continue, " << "'N' for New Data, " << "'Q' to Quit> ";
- cin >> listmore;
- if ((listmore == 'C')||(listmore == 'c'))dividelist = 0;
- else if ((listmore == 'N')||(listmore == 'n'))
- break; // Halt Current Program if New Data is entered, verify and restart
- else if ((listmore == 'Q')||(listmore == 'q'))
- return 0; // End Program
- }
- }
-
- do // This loops valididates user input to enter New Data
- {
- cout << "\tEnter 'C' to Continue, 'Q' to Quit> ";
- cin >> quit;
- cout << "\n";
- }
-
- while ((quit != 'q') &&
- (quit != 'Q') &&
- (quit != 'c') &&
- (quit != 'C'));
- }
-
- cout << endl;
- system("PAUSE"); // Pause program prior to exit
- return EXIT_SUCCESS; // Exit
- }
/* Write the program as a procedural C++ program. Allow the user to input the amount of a mortgage and then select from a menu of mortgage loans: 7 year at 5.35% 15 year at 5.5% 30 year at 5.75% Use an array for the different loans. Display the mortgage payment amount. Then, list the loan balance and interest paid for each payment over the term of the loan. On longer-term loans, the list will scroll off the screen. Do not allow the list to scroll off the screen, but rather display a partial list and then allow the user to continue the list. Allow the user to loop back and enter new data or quit. Insert comments in the program to document the program. */ #include <math.h> // Math Constant #include <cstdlib> // Standard Library #include <iostream> // Defines facilities for basic I/O operations using namespace std; // Namespace standard library int main(int argc, char *argv[]) // Main, argc and *argv give the number and value of the program's command-line arguments { cout << " " << endl; // Empty line before assignment title cout << " ///////////////////////////////////////////////////////////////////////// " << endl; cout << " // // " << endl; cout << " // Calculate and display the mortgage payment amount using the amount // " << endl; cout << " // of the mortgage, the term of the mortgage, and the interest rate // " << endl; cout << " // of the mortgage. The user will enter the amount of the mortgage // " << endl; cout << " // and will select from a menu the amount of years and interest rate. // " << endl; cout << " // The mortgage payment will display and the ammortization table will // " << endl; cout << " // display the loan balance and interest paid. The user will be // " << endl; cout << " // allowed to either continue the ammortization table, enter new // " << endl; cout << " // loan data or quit the program altogether. // " << endl; cout << " // // " << endl; cout << " ///////////////////////////////////////////////////////////////////////// " << endl; cout << " " << endl << endl << endl << endl << endl << endl; double loanAmount, // Amount of the Loan monthlyPayment, // Monthly Payment of the Loan loanBalance, // Balance of the Loan intPaid, // Interest Paid on the Loan amountPaid, // Amount Paid on the Loan intRate[3] = {5.25, 5.50, 5.75}; // Interest Rate of the Loan int numPayments, // Number of Payments paymentCounter, dividelist = 0, // Display partial list length[3] = {7, 15, 30}; // Length of the Loan char listmore; char quit; // Prompt user to quit quit = 'C'; // Quit variable while (quit != 'Q' && quit != 'q') { cout << "\t Enter Loan Amount (*NUMBERS ONLY*): "; cin >> loanAmount; cout << "\t Select Line Number for Length of Loan and Interest Rate " << endl; cout << "\t 1. 7 Years at 5.35% " << endl; cout << "\t 2. 15 Years at 5.50% " << endl; cout << "\t 3. 30 Years at 5.75% " << endl; cout << "\t Enter Line Number Here: "; int choice; cin >> choice; cout << endl; int i; for (i = 0; i < 1; i++) switch (choice) { case 0: cout << endl; break; case 1: cout << "\t You Selected 7 Years at 5.35%" << endl; break; case 2: cout << "\t You Selected 15 Years at 5.50%" << endl; break; case 3: cout << "\t You Selected 30 Years at 5.75%" << endl; break; default: cout << "\t Invalid Line Number" << endl; /* // Still having minor issues with invalid number if (choice != 1,2,3) { cout << "\t Enter Line Number Here: "; int choice; cin >> choice; cout << endl; if (choice != 1,2,3) { cout << "\t You cannot follow directions. " << endl; case 9: cout << "\t Program will now END " << endl; break; } }*/ } cout << endl; monthlyPayment = loanAmount * (intRate[choice] / 1200) / (1 - pow(1 + (intRate[choice] / 1200), - 1 * (length[choice] * 12))); cout << "\t Monthly Payments: $" << monthlyPayment << endl << endl; double numPayments = length[choice] * 12; dividelist = 0; for (paymentCounter = 1; paymentCounter <= numPayments; ++paymentCounter) { // Math Formula for intPaid to set up value for amountPaid intPaid = loanAmount * (intRate[choice] / 1200); amountPaid = monthlyPayment - intPaid; loanBalance = loanAmount - amountPaid; if (loanBalance < 0)loanBalance = 0; loanAmount = loanBalance; if (dividelist == 0) { cout << "\t\tLoan Balance" << "\t\tInterest Paid" << endl; cout << "\t\t____________" << "\t\t_____________" << endl << endl; } cout << "\t\t$" << loanBalance << "\t\t\t$" << intPaid << endl; ++dividelist; // User to Continue, enter New Data or Quit if (dividelist == 12) { cout << endl << endl; cout << "\tEnter 'C' to Continue, " << "'N' for New Data, " << "'Q' to Quit> "; cin >> listmore; if ((listmore == 'C')||(listmore == 'c'))dividelist = 0; else if ((listmore == 'N')||(listmore == 'n')) break; // Halt Current Program if New Data is entered, verify and restart else if ((listmore == 'Q')||(listmore == 'q')) return 0; // End Program } } do // This loops valididates user input to enter New Data { cout << "\tEnter 'C' to Continue, 'Q' to Quit> "; cin >> quit; cout << "\n"; } while ((quit != 'q') && (quit != 'Q') && (quit != 'c') && (quit != 'C')); } cout << endl; system("PAUSE"); // Pause program prior to exit return EXIT_SUCCESS; // Exit }
#include <math.h> // Math Constant #include <cstdlib> // Standard Library #include <iostream> // Defines facilities for basic I/O operations using namespace std; // Namespace standard library int main(int argc, char *argv[]) // Main, argc and *argv give the number and value of the program's command-line arguments { cout << " " << endl; // Empty line before assignment title cout << " ///////////////////////////////////////////////////////////////////////// " << endl; cout << " // // " << endl; cout << " // Calculate and display the mortgage payment amount using the amount // " << endl; cout << " // of the mortgage, the term of the mortgage, and the interest rate // " << endl; cout << " // of the mortgage. The user will enter the amount of the mortgage // " << endl; cout << " // and will select from a menu the amount of years and interest rate. // " << endl; cout << " // The mortgage payment will display and the ammortization table will // " << endl; cout << " // display the loan balance and interest paid. The user will be // " << endl; cout << " // allowed to either continue the ammortization table, enter new // " << endl; cout << " // loan data or quit the program altogether. // " << endl; cout << " // // " << endl; cout << " ///////////////////////////////////////////////////////////////////////// " << endl; cout << " " << endl << endl << endl << endl << endl << endl; double loanAmount, // Amount of the Loan monthlyPayment, // Monthly Payment of the Loan loanBalance, // Balance of the Loan intPaid, // Interest Paid on the Loan amountPaid, // Amount Paid on the Loan intRate[3] = {5.25, 5.50, 5.75}; // Interest Rate of the Loan int numPayments, // Number of Payments paymentCounter, dividelist = 0, // Display partial list length[3] = {7, 15, 30}; // Length of the Loan char listmore; char quit; // Prompt user to quit quit = 'C'; // Quit variable while (quit != 'Q' && quit != 'q') { cout << "\t Enter Loan Amount (*NUMBERS ONLY*): "; cin >> loanAmount; cout << "\t Select Line Number for Length of Loan and Interest Rate " << endl; cout << "\t 1. 7 Years at 5.35% " << endl; cout << "\t 2. 15 Years at 5.50% " << endl; cout << "\t 3. 30 Years at 5.75% " << endl; cout << "\t Enter Line Number Here: "; int choice; cin >> choice; cout << endl; int i; for (i = 0; i < 1; i++) switch (choice) { case 0: cout << endl; break; case 1: length[1] = 7; intRate[1] = 5.35; cout << "\t You Selected 7 Years at 5.35%" << endl; break; case 2: length[2] = 15; intRate[2]= 5.50; cout << "\t You Selected 15 Years at 5.50%" << endl; break; case 3: length[3] = 30; intRate[3] = 5.75; cout << "\t You Selected 30 Years at 5.75%" << endl; break; default: cout << "\t Invalid Line Number" << endl; /* // Still having minor issues with invalid number if (choice != 1,2,3) { cout << "\t Enter Line Number Here: "; int choice; cin >> choice; cout << endl; if (choice != 1,2,3) { cout << "\t You cannot follow directions. " << endl; case 9: cout << "\t Program will now END " << endl; break; } }*/ } cout << endl; monthlyPayment = loanAmount * (intRate[choice] / 1200) / (1 - pow(1 + (intRate[choice] / 1200), - 1 * (length[choice] * 12))); cout << "\t Monthly Payments: $" << monthlyPayment << endl << endl; double numPayments = length[choice] * 12; dividelist = 0; for (paymentCounter = 1; paymentCounter <= numPayments; ++paymentCounter) { // Math Formula for intPaid to set up value for amountPaid intPaid = loanAmount * (intRate[choice] / 1200); amountPaid = monthlyPayment - intPaid; loanBalance = loanAmount - amountPaid; if (loanBalance < 0)loanBalance = 0; loanAmount = loanBalance; if (dividelist == 0) { cout << "\t\tLoan Balance" << "\t\tInterest Paid" << endl; cout << "\t\t____________" << "\t\t_____________" << endl << endl; } cout << "\t\t$" << loanBalance << "\t\t\t$" << intPaid << endl; ++dividelist; // User to Continue, enter New Data or Quit if (dividelist == 12) { cout << endl << endl; cout << "\tEnter 'C' to Continue, " << "'N' for New Data, " << "'Q' to Quit> "; cin >> listmore; if ((listmore == 'C')||(listmore == 'c'))dividelist = 0; else if ((listmore == 'N')||(listmore == 'n')) break; // Halt Current Program if New Data is entered, verify and restart else if ((listmore == 'Q')||(listmore == 'q')) return 0; // End Program } } do // This loops valididates user input to enter New Data { cout << "\tEnter 'C' to Continue, 'Q' to Quit> "; cin >> quit; cout << "\n"; } while ((quit != 'q') && (quit != 'Q') && (quit != 'c') && (quit != 'C')); } cout << endl; system("PAUSE"); // Pause program prior to exit return EXIT_SUCCESS; // Exit }
#include <cmath> // Math Constant #include <cstdlib> // Standard Library #include <iostream> // Defines facilities for basic I/O operations #include <iomanip> // Defines facilities for basic I/O operations // cout << fixed << showpoint << setprecision(2) using namespace std; // Namespace standard library int main(int argc, char *argv[]) // Main, argc and *argv give the number and value of the program's command-line arguments { cout << " " << endl; // Empty line before assignment title cout << " ///////////////////////////////////////////////////////////////////////// " << endl; cout << " // // " << endl; cout << " // Calculate and display the mortgage payment amount using the amount // " << endl; cout << " // of the mortgage, the term of the mortgage, and the interest rate // " << endl; cout << " // of the mortgage. The user will enter the amount of the mortgage // " << endl; cout << " // and will select from a menu the amount of years and interest rate. // " << endl; cout << " // The mortgage payment will display and the ammortization table will // " << endl; cout << " // display the loan balance and interest paid. The user will be // " << endl; cout << " // allowed to either continue the ammortization table, enter new // " << endl; cout << " // loan data or quit the program altogether. // " << endl; cout << " // // " << endl; cout << " ///////////////////////////////////////////////////////////////////////// " << endl; cout << " " << endl << endl << endl << endl << endl << endl; double loanAmount, // Amount of the Loan monthlyPayment, // Monthly Payment of the Loan loanBalance, // Balance of the Loan intPaid, // Interest Paid on the Loan amountPaid, // Amount Paid on the Loan intRate[3] = {5.25, 5.50, 5.75}; // Interest Rate of the Loan int numPayments, // Number of Payments paymentCounter, dividelist = 0, // Display partial list length[3] = {7, 15, 30}; // Length of the Loan char listmore; char quit; // Prompt user to quit quit = 'C'; // Quit variable while (quit != 'Q' && quit != 'q') { cout << "\t Enter Loan Amount (*NUMBERS ONLY*): "; cin >> loanAmount; cout << "\t Select Line Number for Length of Loan and Interest Rate " << endl; cout << "\t 1. 7 Years at 5.35% " << endl; cout << "\t 2. 15 Years at 5.50% " << endl; cout << "\t 3. 30 Years at 5.75% " << endl; cout << "\t Enter Line Number Here: "; int choice; cin >> choice; cout << endl << endl << endl; int i; for (i = 0; i < 1; i++) switch (choice) { case 0: cout << endl; break; case 1: length[1] = 7; intRate[1] = 5.35; cout << "\t You Selected 7 Years and 5.35%" << endl; break; case 2: length[2] = 15; intRate[2]= 5.50; cout << "\t You Selected 15 Years at 5.50%" << endl; break; case 3: length[3] = 30; intRate[3] = 5.75; cout << "\t You Selected 30 Years at 5.75%" << endl; break; default: cout << "\t Invalid Line Number" << endl; } cout << endl; monthlyPayment = loanAmount * (intRate[choice] / 1200) / (1 - pow(1 + (intRate[choice] / 1200), - 1 * (length[choice] * 12))); cout << "\t Monthly Payments: $" << monthlyPayment << endl << endl; double numPayments = length[choice] * 12; dividelist = 0; for (paymentCounter = 1; paymentCounter <= numPayments; ++paymentCounter) { // Math Formula for intPaid to set up value for amountPaid intPaid = loanAmount * (intRate[choice] / 1200); amountPaid = monthlyPayment - intPaid; loanBalance = loanAmount - amountPaid; if (loanBalance < 0)loanBalance = 0; loanAmount = loanBalance; if (dividelist == 0) { cout << "\t\tLoan Balance" << "\t\tInterest Paid" << endl; cout << "\t\t____________" << "\t\t_____________" << endl << endl; } cout << fixed << showpoint << setprecision(2) // Sets the number of digits printed to the right of the decimal point. << "\t\t$" << loanBalance << "\t\t$" << intPaid << endl; ++dividelist; // User to Continue, enter New Data or Quit if (dividelist == 12) { cout << endl << endl; cout << "\tEnter 'C' to Continue, " << "'N' for New Data, " << "'Q' to Quit> "; cin >> listmore; if ((listmore == 'C')||(listmore == 'c'))dividelist = 0; else if ((listmore == 'N')||(listmore == 'n')) break; // Halt Current Program if New Data is entered, verify and restart else if ((listmore == 'Q')||(listmore == 'q')) return 0; // End Program } } do // This loops valididates user input to enter New Data { cout << "\tEnter 'C' to Continue, 'Q' to Quit> "; cin >> quit; cout << "\n"; } while ((quit != 'q') && (quit != 'Q') && (quit != 'c') && (quit != 'C')); } cout << endl; system("PAUSE"); // Pause program prior to exit return EXIT_SUCCESS; // Exit }
| DaniWeb Message | |
| Cancel Changes | |