help with mortgage program

errors when compiling

Page 1 of 1

8 Replies - 4391 Views - Last Post: 13 October 2008 - 11:15 AM Rate Topic: -----

#1 marol44   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 12-October 08

help with mortgage program

Posted 12 October 2008 - 10:46 AM

I am getting errors when I compile my code. Any help would be greatly appreciated.

#include <iostream>		 
#include <iomanip> 
#include <cmath>	 
#include <cctype> 
#include <stdlib.h> 
#include <sstream>	 
#include <cstdlib> 
  
using namespace std; 
  
void MortSched(double, double, int); 
  
//The structure below will contain the mortgage information 
  
struct PaymentInfo 
{ 
	   float fMonPayment; 
	   float fYears; 
	   float fInterestRate; 
	   float fLoanAmount; 
}; 
  
int GetPayment(); 
int LoopAgain(); 
float UserInput(); 
void GetPaymentInfo(PaymentInfo& payinfo); 
void DeterminePayment(PaymentInfo& payinfo); 
void ShowPayment(PaymentInfo& payinfo); 
char iResponse; 
  
//The following section of code will validate user input.  We only want the user to 
//be able to enter numbers or the decimal. 
  
class nondigit 
{ 
	  public: 
			 bool operator() (char c) 
			 { 
				  if (c =='.') 
				  { 
						return !1; 
				  } 
						else 
						{ 
							return !isdigit(c); 
						} 
			 } 
}; 
  
//This next section of code will accept the user input and validate all input 
//the user enters.  The main function here is to validate all user input. 
  
float UserInput() 
{ 
	  float output; 
	  string input; 
	  cin >> input; 
	  if (find_if(input.begin(), input.end(), nondigit()) == input.end()) 
	  { 
								 stringstream mc(input); 
								 mc >> output; 
	  } 
								 else 
								 { 
									 cout << input << " is not a valid number! Please try again!\n"; 
									 output = UserInput(); 
								  } 
									 return output; 
} 
  
//The next section of code prompts the user to enter the amounts for the mortgage calculator 
  
void GetPaymentInfo(PaymentInfo& payinfo) 
{ 
	 cout << "********************Mortgage Calculator********************\n"; 
	 cout << "What is the amount of the mortgage?  For example 200000\n"; 
	 payinfo.fLoanAmount = UserInput(); 
	 cout << "What is the amount of years the mortgage will be financed? For example 30\n"; 
	 payinfo.fYears = UserInput(); 
	 cout << "What is the interest rate? For example 5.75\n"; 
	 payinfo.fInterestRate = UserInput(); 
} 
  
//The following code calculates the monthly payment amount based on the users input 
  
void DeterminePayment(PaymentInfo& payinfo) 
{ 
	 payinfo.fMonPayment = (0); 
	 { 
						 payinfo.fLoanAmount = (0); 
						 { 
											 ((payinfo.fInterestRate / 100) / 12 * pow((payinfo.fInterestRate / 100) / 12 + 1, (payinfo.fYears * 12))) 
											 / 
											 (pow((payinfo.fInterestRate / 100) / 12 + 1, (payinfo.fYears * 12))-1); 
						 } 
	  } 
}										
  
//The following code displays the payment amount based on the users input 
  
void ShowPayment(PaymentInfo& payinfo) 
{ 
	 cout << "Amount of mortgage = $\n" << payinfo.fLoanAmount << endl; 
	 cout << "Years financed = \n" << payinfo.fYears << endl; 
	 cout << "Interest Rate = \n" << payinfo.fInterestRate << endl; 
	 cout << "Monthly Payment Amount = $\n" << payinfo.fMonPayment << endl; 
} 
  
//The next section will allow the user to run the program again or exit the program 
  
int LoopAgain() 
{ 
	int run = 0; 
	int loop = 0; 
	char mychar[7]; 
	cout << "To run this program again, please press 1, and then press enter.\n"; 
	cout << "To exit this program, please press 2, and then press enter.\n"; 
	cin >> ws; 
	cin.getline(mychar,7); 
	if (mychar[0] == '1') 
	{ 
				  cout << "Thank you for choosing option 1.  This program will run again.\n"; 
				  run = 1; 
	} 
				  else 
				  { 
					  cout << "Thank you for choosing option 2.  This program will now exit.\n"; 
					  run = 0; 
				  } 
					  return run; 
} 
  
int runGetPayment() 
{ 
	float fMonPayment = 0.00; 
	PaymentInfo structPaymentInfo; 
	GetPaymentInfo(structPaymentInfo); 
	DeterminePayment(structPaymentInfo); 
	ShowPayment(structPaymentInfo); 
	int again = LoopAgain(); 
	return again; 
} 
  
//We will offer the user the option to view the amortization schedule 
int main() 
{ 
cout.setf(ios::fixed); 
cout.setf(ios::showpoint); 
cout.precision(2); 
  
				  cout<< endl << "Would you like to view the Amortization Schedule? Press Y or N.\n"; 
				  iResponse = getchar(); 
  
if(iResponse == 'Y' || iResponse == 'y') 
  
   MortSched(fLoanAmount, fInterestRate, fYears); 
			iResponse = '\n';	
} 
			else 
			{	
				iResponse = '\n'; 
			}	   
		cout << endl << "Would you like to run this again? Press Y or N. "; 
		iResponse = getch(); 
		do 
  
} 
	while((iResponse == 'Y') || (iResponse == 'y')); 
  
	return 0; 
} 
//The following code will calculate the amortization schedule. 
  
void MortSched(double fLoanAmount, double fInterestRate, int fYears) 
{ 
	double Balance, PaidInt, MonPayment, LoanAmount, Principle; 
	int lineCount = 0; 
	cout.setf(ios::left); 
	MonPayment = calcPayment(&LoanAmount, &InterestRate, &Years); 
	Balance = LoanAmount;	   
	for (int InstallNumber = 1; InstallNumber <= Years; ++InstallNumber) 
	{ 
		if (lineCount == 0) 
		{ 
			system("CLS"); 
			cout << "Payment		  Loan		  Principle		  Interest" << endl; 
			cout << "No.			  Balance	   Payment			Payment" << endl; 
			cout << "**************************************************  ********" << endl;  
		} 
  
		PaidInt = Balance * (InterestRate / (12 * 100)); 
		LoanAmount = MonPayment - PaidInt; 
		Principle = Balance - Principle; 
		cout << setw(12) << InstallNumber 
			 << setw(15) << Balance 
			   << setw(15) << MonPayment 
			 << setw(15) << PaidInt << endl; 
		Balance = Principle;		 
		if (lineCount==12) 
		   { 
			system("pause"); 
			lineCount = 0; 
			}  
						   else 
		{ 
			lineCount++; 
		} 
} 
  
	cout.unsetf(ios::left); 
	return; 
}



Is This A Good Question/Topic? 0
  • +

Replies To: help with mortgage program

#2 BetaWar   User is offline

  • #include "soul.h"
  • member icon

Reputation: 1695
  • View blog
  • Posts: 8,592
  • Joined: 07-September 06

Re: help with mortgage program

Posted 12 October 2008 - 11:04 AM

What errors are you getting?
Was This Post Helpful? 0
  • +
  • -

#3 marol44   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 12-October 08

Re: help with mortgage program

Posted 12 October 2008 - 11:08 AM

1>------ Build started: Project: FirstProject, Configuration: Debug Win32 ------
1>Compiling...
1>FirstProject.cpp
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(10) : error C2871: 'std' : a namespace with this name does not exist
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(46) : error C3861: 'isdigit': identifier not found
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(57) : error C2065: 'string' : undeclared identifier
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(57) : error C2146: syntax error : missing ';' before identifier 'input'
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(57) : error C2065: 'input' : undeclared identifier
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(58) : error C2065: 'cin' : undeclared identifier
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(59) : error C2228: left of '.begin' must have class/struct/union
1> type is ''unknown-type''
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(59) : error C2228: left of '.end' must have class/struct/union
1> type is ''unknown-type''
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(59) : error C2228: left of '.end' must have class/struct/union
1> type is ''unknown-type''
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(59) : error C3861: 'find_if': identifier not found
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(61) : error C2065: 'stringstream' : undeclared identifier
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(61) : error C2146: syntax error : missing ';' before identifier 'mc'
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(61) : error C3861: 'mc': identifier not found
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(66) : error C2065: 'cout' : undeclared identifier
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(93) : error C3861: 'pow': identifier not found
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(95) : error C3861: 'pow': identifier not found
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(104) : error C2065: 'endl' : undeclared identifier
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(119) : error C2065: 'ws' : undeclared identifier
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(120) : error C2228: left of '.getline' must have class/struct/union
1> type is ''unknown-type''
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(148) : error C2228: left of '.setf' must have class/struct/union
1> type is ''unknown-type''
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(148) : error C2653: 'ios' : is not a class or namespace name
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(148) : error C2065: 'fixed' : undeclared identifier
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(149) : error C2228: left of '.setf' must have class/struct/union
1> type is ''unknown-type''
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(149) : error C2653: 'ios' : is not a class or namespace name
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(149) : error C2065: 'showpoint' : undeclared identifier
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(150) : error C2228: left of '.precision' must have class/struct/union
1> type is ''unknown-type''
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(157) : error C2065: 'fLoanAmount' : undeclared identifier
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(157) : error C2065: 'fInterestRate' : undeclared identifier
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(157) : error C2065: 'fYears' : undeclared identifier
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(160) : error C2059: syntax error : 'else'
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(161) : error C2143: syntax error : missing ';' before '{'
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(161) : error C2447: '{' : missing function header (old-style formal list?)
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(164) : error C2143: syntax error : missing ';' before '<<'
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(164) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(164) : error C2371: 'cout' : redefinition; different basic types
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(165) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(165) : error C2371: 'iResponse' : redefinition; different basic types
1> c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(30) : see declaration of 'iResponse'
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(165) : error C3861: 'getch': identifier not found
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(167) : error C2059: syntax error : '}'
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(167) : error C2143: syntax error : missing ';' before '}'
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(167) : error C2059: syntax error : '}'
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(170) : error C2059: syntax error : 'return'
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(171) : error C2059: syntax error : '}'
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(171) : error C2143: syntax error : missing ';' before '}'
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(171) : error C2059: syntax error : '}'
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(175) : error C2143: syntax error : missing ';' before '{'
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\firstproject\firstproject\firstproject.cpp(175) : error C2447: '{' : missing function header (old-style formal list?)
1>Build log was saved at "file://c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\FirstProject\FirstProject\Debug\BuildLog.htm"
1>FirstProject - 47 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Was This Post Helpful? 0
  • +
  • -

#4 Pontus   User is offline

  • Cattlebruiser

Reputation: 18
  • View blog
  • Posts: 612
  • Joined: 28-December 06

Re: help with mortgage program

Posted 12 October 2008 - 12:34 PM

Wich IDE are you using?
Was This Post Helpful? 0
  • +
  • -

#5 marol44   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 12-October 08

Re: help with mortgage program

Posted 12 October 2008 - 12:42 PM

View Postmanhaeve5, on 12 Oct, 2008 - 12:34 PM, said:

Wich IDE are you using?

I'm using Visual Studio
Was This Post Helpful? 0
  • +
  • -

#6 Pontus   User is offline

  • Cattlebruiser

Reputation: 18
  • View blog
  • Posts: 612
  • Joined: 28-December 06

Re: help with mortgage program

Posted 12 October 2008 - 01:17 PM

Try using DevC++. It far more easy to use. Maybe that'll help.
Was This Post Helpful? 0
  • +
  • -

#7 marol44   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 12-October 08

Re: help with mortgage program

Posted 12 October 2008 - 01:58 PM

I'm having an issue with the syntax and I also have an issue with undefined variables. Even if I use a different IDE I will still have the same issue.
Was This Post Helpful? 0
  • +
  • -

#8 marol44   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 12-October 08

Re: help with mortgage program

Posted 12 October 2008 - 02:19 PM

OK I've made a change and now I'm down to 21 erors Can someone please take a look and let me know where I'm going wrong.

#include "stdafx.h"
#include <iostream>		
#include <iomanip>
#include <cmath>	
#include <cctype>
#include <stdlib.h>
#include <sstream>	
#include <cstdlib>


using namespace std;

void MortSched(double, double, int);

//The structure below will contain the mortgage information

struct PaymentInfo
{
	   float fMonPayment;
	   float fYears;
	   float fInterestRate;
	   float fLoanAmount;
};
	   
int GetPayment();
int LoopAgain();
float UserInput();
void GetPaymentInfo(PaymentInfo& payinfo);
void DeterminePayment(PaymentInfo& payinfo);
void ShowPayment(PaymentInfo& payinfo);
char iResponse;

//The following section of code will validate user input.  We only want the user to
//be able to enter numbers or the decimal.

class nondigit
{
	  public:
			 bool operator() (char c)
			 {
				  if (c =='.')
				  {
						return !1;
				  }
						else
						{
							return !isdigit(c);
						}
			 }
};
							
//This next section of code will accept the user input and validate all input
//the user enters.  The main function here is to validate all user input.

float UserInput()
{
	  float output;
	  string input;
	  cin >> input;
	  if (find_if(input.begin(), input.end(), nondigit()) == input.end())
	  {
								 stringstream mc(input);
								 mc >> output;
	  }
								 else
								 {
									 cout << input << " is not a valid number! Please try again!\n";
									 output = UserInput();
								  }
									 return output;
}
									 
//The next section of code prompts the user to enter the amounts for the mortgage calculator

void GetPaymentInfo(PaymentInfo& payinfo)
{
	 cout << "********************Mortgage Calculator********************\n";
	 cout << "What is the amount of the mortgage?  For example 200000\n";
	 payinfo.fLoanAmount = UserInput();
	 cout << "What is the amount of years the mortgage will be financed? For example 30\n";
	 payinfo.fYears = UserInput();
	 cout << "What is the interest rate? For example 5.75\n";
	 payinfo.fInterestRate = UserInput();
}
	 
//The following code calculates the monthly payment amount based on the users input

void DeterminePayment(PaymentInfo& payinfo)
{
	 payinfo.fMonPayment = (0);
	 {
						 payinfo.fLoanAmount = (0);
						 {
											 ((payinfo.fInterestRate / 100) / 12 * pow((payinfo.fInterestRate / 100) / 12 + 1, (payinfo.fYears * 12)))
											 /
											 (pow((payinfo.fInterestRate / 100) / 12 + 1, (payinfo.fYears * 12))-1);
						 }
	  }
}									   
											 
//The following code displays the payment amount based on the users input

void ShowPayment(PaymentInfo& payinfo)
{
	 cout << "Amount of mortgage = $\n" << payinfo.fLoanAmount << endl;
	 cout << "Years financed = \n" << payinfo.fYears << endl;
	 cout << "Interest Rate = \n" << payinfo.fInterestRate << endl;
	 cout << "Monthly Payment Amount = $\n" << payinfo.fMonPayment << endl;
}
	 
//The next section will allow the user to run the program again or exit the program

int LoopAgain()
{
	int run = 0;
	int loop = 0;
	char mychar[7];
	cout << "To run this program again, please press 1, and then press enter.\n";
	cout << "To exit this program, please press 2, and then press enter.\n";
	cin >> ws;
	cin.getline(mychar,7);
	if (mychar[0] == '1')
	{
				  cout << "Thank you for choosing option 1.  This program will run again.\n";
				  run = 1;
	}
				  else
				  {
					  cout << "Thank you for choosing option 2.  This program will now exit.\n";
					  run = 0;
				  }
					  return run;
}
					  
int runGetPayment()
{
	float fMonPayment = 0.00;
	PaymentInfo structPaymentInfo;
	GetPaymentInfo(structPaymentInfo);
	DeterminePayment(structPaymentInfo);
	ShowPayment(structPaymentInfo);
	int again = LoopAgain();
	return again;
}
	
//We will offer the user the option to view the amortization schedule
int main()
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

				  cout<< endl << "Would you like to view the Amortization Schedule? Press Y or N.\n";
				  iResponse = getchar();

if(iResponse == 'Y' || iResponse == 'y')

   MortSched(fLoanAmount, fInterestRate, fYears);
			iResponse = '\n';   
}
			else
			{   
				iResponse = '\n';
			}	  
		cout << endl << "Would you like to run this again? Press Y or N. ";
		iResponse = getch();

}
	while((iResponse == 'Y') || (iResponse == 'y'));

	return 0;
}
//The following code will calculate the amortization schedule.

void MortSched(double fLoanAmount, double fInterestRate, int fYears)
{
	double Balance, PaidInt, MonPayment, LoanAmount, Principle;
	int lineCount = 0;
	cout.setf(ios::left);
	MonPayment = calcPayment(&LoanAmount, &InterestRate, &Years);
	Balance = LoanAmount;	  
	for (int InstallNumber = 1; InstallNumber <= Years; ++InstallNumber)
	{
		if (lineCount == 0)
		{
			system("CLS");
			cout << "Payment		  Loan		  Principle		  Interest" << endl;
			cout << "No.			  Balance	   Payment			Payment" << endl;
			cout << "**********************************************************" << endl; 
		}

		PaidInt = Balance * (InterestRate / (12 * 100));
		LoanAmount = MonPayment - PaidInt;
		Principle = Balance - Principle;
		cout << setw(12) << InstallNumber
			 << setw(15) << Balance
			   << setw(15) << MonPayment
			 << setw(15) << PaidInt << endl;
		Balance = Principle;		
		if (lineCount==12)
		   {
			system("pause");
			lineCount = 0;
		   } 
						   else
		{
			lineCount++;
		}
}

	cout.unsetf(ios::left);
	return;
}

Was This Post Helpful? 0
  • +
  • -

#9 Pontus   User is offline

  • Cattlebruiser

Reputation: 18
  • View blog
  • Posts: 612
  • Joined: 28-December 06

Re: help with mortgage program

Posted 13 October 2008 - 11:15 AM

Sry, cant help. I don't have VS.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1