Hey, everyone. I am having getting my code to work. I have tried to add in a selection for the users. Not to mention I think I broke my table.

here is the errors I get.

1>c:\users\keith\documents\visual studio 2005\projects\wk5mortgage\wk5mortgage\wk5m.cpp(51) : error C2446: '!=' : no conversion from 'int' to 'void (__cdecl *)(int)'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\keith\documents\visual studio 2005\projects\wk5mortgage\wk5mortgage\wk5m.cpp(51) : error C2040: '!=' : 'void (__cdecl *)(int)' differs in levels of indirection from 'int'
1>c:\users\keith\documents\visual studio 2005\projects\wk5mortgage\wk5mortgage\wk5m.cpp(51) : error C2446: '!=' : no conversion from 'int' to 'void (__cdecl *)(int)'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\keith\documents\visual studio 2005\projects\wk5mortgage\wk5mortgage\wk5m.cpp(51) : error C2040: '!=' : 'void (__cdecl *)(int)' differs in levels of indirection from 'int'
1>c:\users\keith\documents\visual studio 2005\projects\wk5mortgage\wk5mortgage\wk5m.cpp(62) : error C2317: 'try' block starting on line '53' has no catch handlers
1>c:\users\keith\documents\visual studio 2005\projects\wk5mortgage\wk5mortgage\wk5m.cpp(62) : error C2181: illegal else without matching if
1>c:\users\keith\documents\visual studio 2005\projects\wk5mortgage\wk5mortgage\wk5m.cpp(62) : warning C4390: ';' : empty controlled statement found; is this the intent?
1>c:\users\keith\documents\visual studio 2005\projects\wk5mortgage\wk5mortgage\wk5m.cpp(81) : error C2440: '=' : cannot convert from 'double [2]' to 'float'
1> There is no context in which this conversion is possible
1>c:\users\keith\documents\visual studio 2005\projects\wk5mortgage\wk5mortgage\wk5m.cpp(82) : error C2440: '=' : cannot convert from 'double [2]' to 'double'
1> There is no context in which this conversion is possible
1>c:\users\keith\documents\visual studio 2005\projects\wk5mortgage\wk5mortgage\wk5m.cpp(85) : error C2440: '=' : cannot convert from 'double [2]' to 'float'
1> There is no context in which this conversion is possible
1>c:\users\keith\documents\visual studio 2005\projects\wk5mortgage\wk5mortgage\wk5m.cpp(86) : error C2440: '=' : cannot convert from 'double [2]' to 'double'
1> There is no context in which this conversion is possible
1>c:\users\keith\documents\visual studio 2005\projects\wk5mortgage\wk5mortgage\wk5m.cpp(89) : error C2440: '=' : cannot convert from 'double [2]' to 'float'
1> There is no context in which this conversion is possible
1>c:\users\keith\documents\visual studio 2005\projects\wk5mortgage\wk5mortgage\wk5m.cpp(90) : error C2440: '=' : cannot convert from 'double [2]' to 'double'
1> There is no context in which this conversion is possible
1>c:\users\keith\documents\visual studio 2005\projects\wk5mortgage\wk5mortgage\wk5m.cpp(139) : error C2446: '==' : no conversion from 'int' to 'char *'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\keith\documents\visual studio 2005\projects\wk5mortgage\wk5mortgage\wk5m.cpp(139) : error C2040: '==' : 'char *' differs in levels of indirection from 'int'
1>c:\users\keith\documents\visual studio 2005\projects\wk5mortgage\wk5mortgage\wk5m.cpp(139) : error C2446: '==' : no conversion from 'int' to 'char *'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\keith\documents\visual studio 2005\projects\wk5mortgage\wk5mortgage\wk5m.cpp(139) : error C2040: '==' : 'char *' differs in levels of indirection from 'int'

// Week 5 Individual Assignment 
// Calculate the monthly payment 

// Include header files


#include <iostream>
#include <iomanip>
#include <math.h>

using std::cout;
using std::endl;
using std::cin;
using std::ios;


//Namespaces
using namespace std;



//Declare and initialize variables
double Amount;
float Term;
double Interest; 
double MnthPayment;
double rPayments;
double newAmount;
double loanPrinciple;
double loanAmount;
double cMnthInterest;
double MnthAmount;
int m = 0;
double values[3][2] = {{7, 5.35},{ 15, 5.5},{30, 5.75}};



int main()
{
double mInterest;
double mTerm;
int select;


bool valid = false;
char repeat;


while (exit != 'y' && exit != 'y')

try	{
		//Data Entry
		cout << "Loan Amount: ";	
		cin >> Amount;
			if (!(cin>> Amount))
			cin.clear(); 
		    cin.ignore(500,'\n');
			throw "Invalid number";
		}
		else if (Amount >1000000 || Amount < 1);{
			cin.clear();
			cin.ignore(500, '\n');
			throw "Please enter up to 1000000";
		}
		cout << endl << "Interest rate choices";  //interest menu
		cout << endl << "1. 7 yrs at 5.35%" << endl;
		cout << endl << "2. 15 yrs at 5.50%" << endl;
		cout << endl << "3. 30 yrs at 5.75%" << endl;
		
		//start of loop for interest
		while (valid == false) {
			cout << "\n Enter your selection: ";
			cin >> select;
			if (( select = 1) || (select == 2) || (select == 3)){
		}
	    // variable input for user select
		switch (select) {
				case 1:
					Term = values[0];
					Interest = values[1];
					break;
				case 2:
					Term = values[2];
					Interest = values[3];
					break;
				case 3: 
					Term = values[4];
					Interest = values[5];
					break;
		}
		
		//cout << endl<< Fetching <<endl << endl;

		mInterest = Interest/(12*100);
		mTerm = Term * 12;


		// Calculate the payment
		MnthPayment = (Amount * pow((1 + mInterest), mTerm)* mInterest)/(pow((1 + mInterest),mTerm)-1.0);

		// Print out for calculations

		cout << "The mortgage payment:$" << MnthPayment <<"\n";
	        
		while (m < rPayments)
		
		//Math to figure out values for table
		MnthPayment = Interest * mInterest;
		Amount = MnthPayment - cMnthInterest;
		newAmount = loanPrinciple - MnthAmount;
		loanAmount = newAmount;

			// Controling the size length of text
			if(m % 12 == 0)
			{
					cout<<"Enter to continue";
					cin.get();
					cout<<endl<<endl;
					cout<<setw(18)<<"Interest";
					cout<<setw(21)<<"New Principle"<<endl<<endl;
			

			m++; 

		//Table
			cout<<setw(4)<<m;
			cout<<setw(20)<<setiosflags(ios::fixed)<<setprecision(2)<<cMnthInterest<<setw(22)<<loanAmount<<endl;
			}
        //prompt for repeat 
		cout <<"Would you like to calculate another loan?" << endl
			 <<"Please enter Y to repeat or any other key to exit: ";
		cin >> repeat;
		cout << endl;

	        
		//assign user input value to control variable
		if (repeat == 'y' || repeat == 'Y') valid = true;
		else 
		{
			cout << endl <<"Thank you for using the Mortgage Calculator"<< endl << endl;
				
			valid = false;
		}
	
	}
	
while(valid == true);

 return 0;
}
// end
Ancient Dragon commented: thanks for using code tags +18

exit? It's a reserved word for a standard function, and you have not declared it otherwise.

Work on your bracing.

Also correct the way you use exception handling in code.

I have made some changes. Here is the errors I am getting now. The good thing is I am getting less errors now.

1>------ Build started: Project: wk5Mortgage, Configuration: Debug Win32 ------
1>Compiling...
1>wk5m.cpp
1>c:\users\keith\documents\visual studio 2005\projects\wk5mortgage\wk5mortgage\wk5m.cpp(59) : error C2059: syntax error : 'if'
1>c:\users\keith\documents\visual studio 2005\projects\wk5mortgage\wk5mortgage\wk5m.cpp(78) : error C2440: '=' : cannot convert from 'double [2]' to 'double'
1> There is no context in which this conversion is possible
1>c:\users\keith\documents\visual studio 2005\projects\wk5mortgage\wk5mortgage\wk5m.cpp(79) : error C2440: '=' : cannot convert from 'double [2]' to 'double'
1> There is no context in which this conversion is possible
1>c:\users\keith\documents\visual studio 2005\projects\wk5mortgage\wk5mortgage\wk5m.cpp(82) : error C2440: '=' : cannot convert from 'double [2]' to 'double'
1> There is no context in which this conversion is possible
1>c:\users\keith\documents\visual studio 2005\projects\wk5mortgage\wk5mortgage\wk5m.cpp(83) : error C2440: '=' : cannot convert from 'double [2]' to 'double'
1> There is no context in which this conversion is possible
1>c:\users\keith\documents\visual studio 2005\projects\wk5mortgage\wk5mortgage\wk5m.cpp(86) : error C2440: '=' : cannot convert from 'double [2]' to 'double'
1> There is no context in which this conversion is possible
1>c:\users\keith\documents\visual studio 2005\projects\wk5mortgage\wk5mortgage\wk5m.cpp(87) : error C2440: '=' : cannot convert from 'double [2]' to 'double'
1> There is no context in which this conversion is possible
1>c:\users\keith\documents\visual studio 2005\projects\wk5mortgage\wk5mortgage\wk5m.cpp(155) : fatal error C1071: unexpected end of file found in comment
1>Build log was saved at "file://c:\Users\Keith\Documents\Visual Studio 2005\Projects\wk5Mortgage\wk5Mortgage\Debug\BuildLog.htm"
1>wk5Mortgage - 8 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

// Week 5 Individual Assignment 
// Calculate the monthly payment, give users to have selection for yrs and interest rate. 

// Include header files


#include <iostream>
#include <iomanip>
#include <cmath>


using std::endl;
using std::cin;
using std::ios;


//Namespaces
using namespace std;



//Declare and initialize variables
double Amount;
double Term;
double Interest; 
double MnthPayment;
double rPayments;
double newAmount;
double loanPrinciple;
double loanAmount;
double cMnthInterest;
double MnthAmount;
int m = 0;
double values[3][2] = {{7, 5.35},{ 15, 5.5},{30, 5.75}};



int main()
{
double mInterest;
double mTerm;
int select;


bool indic=false;
char repeat;

do	{
		//Data Entry
		cout << "Loan Amount: ";	
		cin >> Amount;
		if (!(cin>> Amount))
			cin.clear(); 
		    cin.ignore(500,'\n');
			throw "Invalid number";
		}
		else if (Amount >1000000 || Amount < 1);{
			cin.clear();
			cin.ignore(500, '\n');
			throw "Please enter up to 1000000";
		}
		cout << endl << "Interest rate choices";  //interest menu
		cout << endl << "1. 7 yrs at 5.35%" << endl;
		cout << endl << "2. 15 yrs at 5.50%" << endl;
		cout << endl << "3. 30 yrs at 5.75%" << endl;
		
		//start of loop for interest
		while (indic == false) {
			cout << "\n Enter your selection: ";
			cin >> select;
			if (( select = 1) || (select == 2) || (select == 3)){
		}
	    // variable input for user select
		switch (select) {
				case 1:
					Term = values[0];
					Interest = values[1];
					break;
				case 2:
					Term = values[2];
					Interest = values[3];
					break;
				case 3: 
					Term = values[4];
					Interest = values[5];
					break;
		}
		
		//cout << endl<< Fetching <<endl << endl;

		mInterest = Interest/(12*100);
		mTerm = Term * 12;


		// Calculate the payment
		MnthPayment = (Amount * pow((1 + mInterest), mTerm)* mInterest)/(pow((1 + mInterest),mTerm)-1.0);

	        
		// Print out for calculations

		cout << "The mortgage payment:$" << MnthPayment <<"\n";
	        
		//prompt for repeat 
		cout<<setiosflags(ios::fixed)<<setprecision(2);
		system("pause");
		cout << endl;
		system("cls");
		cout <<"Month              Balance              Interest Paid"<<endl;
		cout <<"-----              -------              -------------"<<endl;
		m=1;
		loanAmount=Amount;
		while (m <= mTerm)
		{ 

			//Math to figure out values for table
			cMnthInterest = loanAmount * mInterest;
			MnthAmount = MnthPayment - cMnthInterest;
			loanAmount = loanAmount - MnthAmount;
			
			//Table
			cout<<setw(4)<<m<<setw(15)<<"$"<<cMnthInterest<<setw(15)<<"$"<<loanAmount<<endl;

			// Controling the size length of text
			if(m % 12 == 0)
			
					
					system("pause");
					system("cls");
					cout <<"Month              Balance              Interest Paid"<<endl;
					cout <<"-----              -------              -------------"<<endl;
			}

			m++; 


	        
		//assign user input value to control variable
		/*if (repeat == 'y' || repeat == 'Y') indic = true;
		{
			cout << endl <<"Thank you for using the Mortgage Calculator"
				<< endl << endl;
			indic = false;
		}
	
	
	
while(indic == true);

 return 0;
}
// end

you need an opening brace { between lines 53 and 54 (or at the end of line 53 if that is your coding style) and remove the semicolon at the end of line 58.

lines 78, 81 and 85. values is a 2d array of doubles and you are attempting to use them as if it is a 1d array.

You really need to start reading the error messages better and try to figure out what's causing them. The first error message for any given line number is usually the most important as the compiler will spit out several other error messages as well.

Yea, I couldn't figure out how to fixed that error. Far as the lines I need to find out in Visual C++ 2005 express to display numbers to figure out which number line that is. Thanks for the help let me look that up.

Ok I figured the line numbering out. I still can't get rid of this error.

error C2181: illegal else without matching if

I thinking my syntax is all wrong.

>>Far as the lines I need to find out in Visual C++ 2005 express to display numbers to figure out which number line that is
Just click on the error message and the IDE will move the cursor to the correct line. Also the current line number is always displayed at the bottom of the window.

>>error C2181: illegal else without matching if
I already told you what that error was -- missing opening brace {.

Does this look right I am getting the same error?

{
		if (!(cin>> Amount))
			cin.clear(); 
		    cin.ignore(500,'\n');
			throw "Invalid number";
		}
		else if (Amount >1000000 || Amount < 1)
		{
			cin.clear();
			cin.ignore(500, '\n');
			throw "Please enter up to 1000000";
		}

No it isn't correct. Read my post #5 very carefully, the very first sentence told you where to put that brace. If you count the braces in the code shipped you just posted you will see that there is an opening brace missing. The opening brace at the top of your last post is misplaced. Move it down to where I told you it belongs.

I appreciate the help. I don't mean to be slow, and confused. I am just haven't a lot of problem just seeing the code.

hows this.

cout << "Loan Amount: ";
	{	
		cin >> Amount;
		if (!(cin>> Amount))
			cin.clear(); 
		    cin.ignore(500,'\n');
			throw "Invalid number";
		}
		else if (Amount >1000000 || Amount < 1)
		{
			cin.clear();
			cin.ignore(500, '\n');
			throw "Please enter up to 1000000";
		}

Here is a hint -- notice the placement of line 4 below. Also why are you asking to input Amount twice ? On line 2 and again on line 3 ?

cout << "Loan Amount: ";
cin >> Amount;
if (!(cin>> Amount))
{	
        cin.clear(); 
        cin.ignore(500,'\n');
        throw "Invalid number";
}
else if (Amount >1000000 || Amount < 1)
{
         cin.clear();
         cin.ignore(500, '\n');
         throw "Please enter up to 1000000";
}

Ok, I see what you are saying. I just wasn't thinking is probably why.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.