954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help with adding users

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
icetux
Newbie Poster
11 posts since Aug 2007
Reputation Points: 28
Solved Threads: 0
 

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

Work on your bracing.

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

Also correct the way you use exception handling in code.

SpS
Posting Pro
599 posts since Aug 2005
Reputation Points: 70
Solved Threads: 32
 

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
icetux
Newbie Poster
11 posts since Aug 2007
Reputation Points: 28
Solved Threads: 0
 

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.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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.

icetux
Newbie Poster
11 posts since Aug 2007
Reputation Points: 28
Solved Threads: 0
 

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.

icetux
Newbie Poster
11 posts since Aug 2007
Reputation Points: 28
Solved Threads: 0
 

>>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 {.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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";
		}
icetux
Newbie Poster
11 posts since Aug 2007
Reputation Points: 28
Solved Threads: 0
 

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.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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";
		}
icetux
Newbie Poster
11 posts since Aug 2007
Reputation Points: 28
Solved Threads: 0
 

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";
}
Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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

icetux
Newbie Poster
11 posts since Aug 2007
Reputation Points: 28
Solved Threads: 0
 

Another problem is thinking you can write a whole program at one sitting, then press "compile" right at the end.

Never write more code than you're prepared to debug.
http://cboard.cprogramming.com/showthread.php?t=88495

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You