473,322 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Arrays for menu choices

10
Hi everyone, I am in the process of writing my last program for my Introduction to C++ class. I have to write a program what will allow a end user to input an amount of a mortgage, from there, I have to get a monthly payment from the following choices which I have to use an array:
- 7 year at 5.35%
-15 year at 5.5%
-30 yea at 5.75%
I am currently reading about arrays, I figured I have to set a two-dimensional array, here is the code I have so far:
//************************************************** *****
//Program: Calculations Payments
//Purpose: To calculate a mortgage monthly payment by the user entering input
// and to have an array of years and Interest rates. This program will list the loan balance as well as the
// interest paid for each payment over the term of the loan.
// In addition, this program will allow the user to enter new data if they wish or to just quit the program.
//Programmer: Cameron Faldeti
//Date: 11/13/06
//School: University of Phoenix
//Class: POS 440: Introduction To C++
//Instructor: John Williams
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <cmath> //Header file in order for a user to calculate math formulas
#include <string> //C++ header file for handling strings
using namespace std;

int main()
{

//Variable declarations
double LoanAmount; //Loan amount entered by the user in order to calculate a mortgage monthly payment
int term; //Years entered by user to use for calculating the monthly payment
double InterestRate; //Interest Rate in percentage used for the loan amount
double MortgageMonthlyPayment;
int NumOfPayments;
double LoanBalance;
int MonthlyMortgagePayment;
double Principle;
double InterestPaid;
char quit;//Allows users to quit the program if they wish
quit = 'G'; //If users enter G, they will have the option to continue
quit = 'g'; //If users enter g, they will have the option to continue
const char NL='\n'; //Originally from Joe Morton
const char TAB='\t'; //Line originally done by Joe Morton
int showlist=0; //To display the list needed in the program
char showmore;
double userEntry(); //Function for getting user input to display the mortgage monthly payment and to display any input errors if
//user enters the wrong kind of data. Original function by programmer Thomas Grzywacz.
//Stores Interest Rate and terms in arrays
double LoanArray[3][3] = {{7, 15, 30}, {5.35, 5.5, 5.75}};

//Allow user to loop back and enter new data or to just quit the program
do
{
cout << fixed << setprecision(2);
cout << "Enter a loan amount: " << "(no commas are allowed in the loan amount)";
LoanAmount = userEntry();
cout << "Loan amount is: $ " << LoanAmount << endl;
//Mortgage monthly calculation
MortgageMonthlyPayment = (LoanAmount* pow((1+ InterestRate/100/12),term*12)* InterestRate/100/12)/((pow((1+InterestRate/100/12),term*12))-1);
cout << "Mortgage monthly payment is: $ " << MortgageMonthlyPayment << endl;
//Lists loan balances and interest paid for each payment of the loan terms
//Lists loan balances and interest paid for each payment of the loan terms
NumOfPayments = term * 12; //Assigns a value to variable NumOfPayments
for(MonthlyMortgagePayment=1; MonthlyMortgagePayment<=NumOfPayments; ++MonthlyMortgagePayment)
{
//For finding the principle and Interest Paid
InterestPaid = LoanAmount * (InterestRate/1200);
Principle = MortgageMonthlyPayment - InterestPaid;
LoanBalance = LoanAmount - Principle;
if (LoanBalance <0)
LoanBalance = 0;
LoanAmount = LoanBalance; //This ends the payments to be made

//Displays a listing of loan balances and Interest paid
if (showlist == 0)
{
cout<< left <<setw(17)<<"Loan balance"<<TAB<<"Interest Paid"<<NL;
cout<< left <<setw(17)<<"---------------"<<TAB<<"-------------"<<NL<<NL;
}
cout<<LoanBalance<<TAB<<TAB<<InterestPaid<<NL;
++showlist;
//To see if the user wants to continue
if (showlist==12)
{
cout<<"Enter 'G' to go on," <<" 'N' for new data," <<" 'Q' to quit>";
cin>>showmore;
if ((showmore=='G')||(showmore=='g'))
showlist=0;
else if ((showmore=='N')||(showmore=='n'))
break;
else if ((showmore=='Q')||(showmore=='q'))
return 0;
}
}
cout << "Press N if you want to enter new data, or press 1 or press 2 to quit the program." << "Choice is: " << endl; //Gives users a chance to continue or quit
cin >> quit;
}while(quit!= '1'&& quit != '2');
system("PAUSE");
return 0; //End of program
}
//Function to find if user entered the data right. Returns userNumEntry original code by Thomas Grzywacz
double userEntry()
{
double userNumEntry = 0; //set user entry value to 0
double testEntry; //Used to test for any data that is entered that are not numbers
bool done = false; //Used to test if user is finished or not
string str = "Data you entered is invalid. \nPlease try again using numbers! "; //Program error message
do
{
cin >> userNumEntry; //Variable for user entry
done = true;
testEntry = cin.peek(); //Peek for entry streams
if (testEntry !=10||userNumEntry <=0) //if testEntry == 10 clear
{
cin.clear(); //value other than 10 is not correct
cin.ignore(200, '\n'); //Ignores the next 200 values until a newline occurs
userNumEntry = 0; //Resets user entry to 0
system("cls"); //clears the screen of any clutter
cout << str << endl; //Outputs program error message
done = false; //Makes done falise to continue do loop
}//end if
}//ends do
while (!done);
return userNumEntry; //value is returned to the main program
}//ends the function.

Any direction will be greatly appreciated.
Nov 14 '06 #1
0 1694

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Mica Cooper | last post by:
Hi, I have a series of Select menus on a page. I am trying to allow the user to click on the Select title and have it popup a help window. This works fine with the following code except that all...
9
by: cmac | last post by:
Greetings, I love the HV menu and have been uning it for a long time. I recently was asked how to make a page for my wife (wedding coming up soon) and my wife would like to have 2 ways to...
1
by: BG | last post by:
We need to put a menu on a page on our website. The menu has to be in the vertical area of a frames page. Go to www.fqvictims.org . The menu choices on the left need to be categorized - and we...
4
by: simon.cigoj | last post by:
I have an javascript made menu and some forms with the dropdown element. When the menu opens and scrolls down the drop down is displeyed over the menu and obscures the menu choices. I have this...
7
by: Ian Hinson | last post by:
I have an Access app that has been distributed with run-time installation to many different customers over many years. It is developed in Access 2000. The custom menu bar has had no problems in...
0
by: Steve Caliendo | last post by:
Hi, How can I make it so that the Frames menu selection will do something? I cannot figure out how to enable any selection from that menu list - they are ALWAYS grayed out. Thanks, Steve
0
by: John Smith | last post by:
If anyone can help, I would very muchly appreciate it. I have a main page that uses the .net 2.0 menu control with the multiview controls as the menu choices. This works fine. One of the menu...
14
namcintosh
by: namcintosh | last post by:
Hello, everyone. Well, let me cut to the chase and explain my problem. I am trying to devise a menu plan that uses the if/else if and the while loop. The program calculates the user's weight...
1
by: Jerry | last post by:
Hi I have built my application but some of my users want to run the application from a usb stick and not have the link in their start menu. If I deploy with oneclick, or wise installer, or the...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.