943,802 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1827
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Sep 1st, 2007
1

Help with adding users

Expand Post »
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'
C++ Syntax (Toggle Plain Text)
  1. // Week 5 Individual Assignment
  2. // Calculate the monthly payment
  3.  
  4. // Include header files
  5.  
  6.  
  7. #include <iostream>
  8. #include <iomanip>
  9. #include <math.h>
  10.  
  11. using std::cout;
  12. using std::endl;
  13. using std::cin;
  14. using std::ios;
  15.  
  16.  
  17. //Namespaces
  18. using namespace std;
  19.  
  20.  
  21.  
  22. //Declare and initialize variables
  23. double Amount;
  24. float Term;
  25. double Interest;
  26. double MnthPayment;
  27. double rPayments;
  28. double newAmount;
  29. double loanPrinciple;
  30. double loanAmount;
  31. double cMnthInterest;
  32. double MnthAmount;
  33. int m = 0;
  34. double values[3][2] = {{7, 5.35},{ 15, 5.5},{30, 5.75}};
  35.  
  36.  
  37.  
  38. int main()
  39. {
  40. double mInterest;
  41. double mTerm;
  42. int select;
  43.  
  44.  
  45. bool valid = false;
  46. char repeat;
  47.  
  48.  
  49. while (exit != 'y' && exit != 'y')
  50.  
  51. try {
  52. //Data Entry
  53. cout << "Loan Amount: ";
  54. cin >> Amount;
  55. if (!(cin>> Amount))
  56. cin.clear();
  57. cin.ignore(500,'\n');
  58. throw "Invalid number";
  59. }
  60. else if (Amount >1000000 || Amount < 1);{
  61. cin.clear();
  62. cin.ignore(500, '\n');
  63. throw "Please enter up to 1000000";
  64. }
  65. cout << endl << "Interest rate choices"; //interest menu
  66. cout << endl << "1. 7 yrs at 5.35%" << endl;
  67. cout << endl << "2. 15 yrs at 5.50%" << endl;
  68. cout << endl << "3. 30 yrs at 5.75%" << endl;
  69.  
  70. //start of loop for interest
  71. while (valid == false) {
  72. cout << "\n Enter your selection: ";
  73. cin >> select;
  74. if (( select = 1) || (select == 2) || (select == 3)){
  75. }
  76. // variable input for user select
  77. switch (select) {
  78. case 1:
  79. Term = values[0];
  80. Interest = values[1];
  81. break;
  82. case 2:
  83. Term = values[2];
  84. Interest = values[3];
  85. break;
  86. case 3:
  87. Term = values[4];
  88. Interest = values[5];
  89. break;
  90. }
  91.  
  92. //cout << endl<< Fetching <<endl << endl;
  93.  
  94. mInterest = Interest/(12*100);
  95. mTerm = Term * 12;
  96.  
  97.  
  98. // Calculate the payment
  99. MnthPayment = (Amount * pow((1 + mInterest), mTerm)* mInterest)/(pow((1 + mInterest),mTerm)-1.0);
  100.  
  101. // Print out for calculations
  102.  
  103. cout << "The mortgage payment:$" << MnthPayment <<"\n";
  104.  
  105. while (m < rPayments)
  106.  
  107. //Math to figure out values for table
  108. MnthPayment = Interest * mInterest;
  109. Amount = MnthPayment - cMnthInterest;
  110. newAmount = loanPrinciple - MnthAmount;
  111. loanAmount = newAmount;
  112.  
  113. // Controling the size length of text
  114. if(m % 12 == 0)
  115. {
  116. cout<<"Enter to continue";
  117. cin.get();
  118. cout<<endl<<endl;
  119. cout<<setw(18)<<"Interest";
  120. cout<<setw(21)<<"New Principle"<<endl<<endl;
  121.  
  122.  
  123. m++;
  124.  
  125. //Table
  126. cout<<setw(4)<<m;
  127. cout<<setw(20)<<setiosflags(ios::fixed)<<setprecision(2)<<cMnthInterest<<setw(22)<<loanAmount<<endl;
  128. }
  129. //prompt for repeat
  130. cout <<"Would you like to calculate another loan?" << endl
  131. <<"Please enter Y to repeat or any other key to exit: ";
  132. cin >> repeat;
  133. cout << endl;
  134.  
  135.  
  136. //assign user input value to control variable
  137. if (repeat == 'y' || repeat == 'Y') valid = true;
  138. else
  139. {
  140. cout << endl <<"Thank you for using the Mortgage Calculator"<< endl << endl;
  141.  
  142. valid = false;
  143. }
  144.  
  145. }
  146.  
  147. while(valid == true);
  148.  
  149. return 0;
  150. }
  151. // end
Last edited by Ancient Dragon; Sep 1st, 2007 at 11:06 pm. Reason: add line numbers
Similar Threads
Reputation Points: 28
Solved Threads: 0
Newbie Poster
icetux is offline Offline
11 posts
since Aug 2007
Sep 1st, 2007
1

Re: Need Help!!!

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

Work on your bracing.
Last edited by Dave Sinkula; Sep 1st, 2007 at 10:46 pm.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Sep 1st, 2007
1

Re: Need Help!!!

Also correct the way you use exception handling in code.
SpS
Reputation Points: 70
Solved Threads: 32
Posting Pro
SpS is offline Offline
598 posts
since Aug 2005
Sep 2nd, 2007
0

Re: Help with adding users

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 ==========


C++ Syntax (Toggle Plain Text)
  1.  
  2. // Week 5 Individual Assignment
  3. // Calculate the monthly payment, give users to have selection for yrs and interest rate.
  4.  
  5. // Include header files
  6.  
  7.  
  8. #include <iostream>
  9. #include <iomanip>
  10. #include <cmath>
  11.  
  12.  
  13. using std::endl;
  14. using std::cin;
  15. using std::ios;
  16.  
  17.  
  18. //Namespaces
  19. using namespace std;
  20.  
  21.  
  22.  
  23. //Declare and initialize variables
  24. double Amount;
  25. double Term;
  26. double Interest;
  27. double MnthPayment;
  28. double rPayments;
  29. double newAmount;
  30. double loanPrinciple;
  31. double loanAmount;
  32. double cMnthInterest;
  33. double MnthAmount;
  34. int m = 0;
  35. double values[3][2] = {{7, 5.35},{ 15, 5.5},{30, 5.75}};
  36.  
  37.  
  38.  
  39. int main()
  40. {
  41. double mInterest;
  42. double mTerm;
  43. int select;
  44.  
  45.  
  46. bool indic=false;
  47. char repeat;
  48.  
  49. do {
  50. //Data Entry
  51. cout << "Loan Amount: ";
  52. cin >> Amount;
  53. if (!(cin>> Amount))
  54. cin.clear();
  55. cin.ignore(500,'\n');
  56. throw "Invalid number";
  57. }
  58. else if (Amount >1000000 || Amount < 1);{
  59. cin.clear();
  60. cin.ignore(500, '\n');
  61. throw "Please enter up to 1000000";
  62. }
  63. cout << endl << "Interest rate choices"; //interest menu
  64. cout << endl << "1. 7 yrs at 5.35%" << endl;
  65. cout << endl << "2. 15 yrs at 5.50%" << endl;
  66. cout << endl << "3. 30 yrs at 5.75%" << endl;
  67.  
  68. //start of loop for interest
  69. while (indic == false) {
  70. cout << "\n Enter your selection: ";
  71. cin >> select;
  72. if (( select = 1) || (select == 2) || (select == 3)){
  73. }
  74. // variable input for user select
  75. switch (select) {
  76. case 1:
  77. Term = values[0];
  78. Interest = values[1];
  79. break;
  80. case 2:
  81. Term = values[2];
  82. Interest = values[3];
  83. break;
  84. case 3:
  85. Term = values[4];
  86. Interest = values[5];
  87. break;
  88. }
  89.  
  90. //cout << endl<< Fetching <<endl << endl;
  91.  
  92. mInterest = Interest/(12*100);
  93. mTerm = Term * 12;
  94.  
  95.  
  96. // Calculate the payment
  97. MnthPayment = (Amount * pow((1 + mInterest), mTerm)* mInterest)/(pow((1 + mInterest),mTerm)-1.0);
  98.  
  99.  
  100. // Print out for calculations
  101.  
  102. cout << "The mortgage payment:$" << MnthPayment <<"\n";
  103.  
  104. //prompt for repeat
  105. cout<<setiosflags(ios::fixed)<<setprecision(2);
  106. system("pause");
  107. cout << endl;
  108. system("cls");
  109. cout <<"Month Balance Interest Paid"<<endl;
  110. cout <<"----- ------- -------------"<<endl;
  111. m=1;
  112. loanAmount=Amount;
  113. while (m <= mTerm)
  114. {
  115.  
  116. //Math to figure out values for table
  117. cMnthInterest = loanAmount * mInterest;
  118. MnthAmount = MnthPayment - cMnthInterest;
  119. loanAmount = loanAmount - MnthAmount;
  120.  
  121. //Table
  122. cout<<setw(4)<<m<<setw(15)<<"$"<<cMnthInterest<<setw(15)<<"$"<<loanAmount<<endl;
  123.  
  124. // Controling the size length of text
  125. if(m % 12 == 0)
  126.  
  127.  
  128. system("pause");
  129. system("cls");
  130. cout <<"Month Balance Interest Paid"<<endl;
  131. cout <<"----- ------- -------------"<<endl;
  132. }
  133.  
  134. m++;
  135.  
  136.  
  137.  
  138. //assign user input value to control variable
  139. /*if (repeat == 'y' || repeat == 'Y') indic = true;
  140. {
  141. cout << endl <<"Thank you for using the Mortgage Calculator"
  142. << endl << endl;
  143. indic = false;
  144. }
  145.  
  146.  
  147.  
  148. while(indic == true);
  149.  
  150.  return 0;
  151. }
  152. // end
  153.  
Last edited by Ancient Dragon; Sep 2nd, 2007 at 9:35 pm. Reason: add line numbers
Reputation Points: 28
Solved Threads: 0
Newbie Poster
icetux is offline Offline
11 posts
since Aug 2007
Sep 2nd, 2007
0

Re: Help with adding users

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.
Last edited by Ancient Dragon; Sep 2nd, 2007 at 9:42 pm.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
Sep 2nd, 2007
0

Re: Help with adding users

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.
Reputation Points: 28
Solved Threads: 0
Newbie Poster
icetux is offline Offline
11 posts
since Aug 2007
Sep 2nd, 2007
0

Re: Help with adding users

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.
Reputation Points: 28
Solved Threads: 0
Newbie Poster
icetux is offline Offline
11 posts
since Aug 2007
Sep 2nd, 2007
0

Re: Help with adding users

>>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 {.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
Sep 2nd, 2007
0

Re: Help with adding users

Does this look right I am getting the same error?


C++ Syntax (Toggle Plain Text)
  1. {
  2. if (!(cin>> Amount))
  3. cin.clear();
  4. cin.ignore(500,'\n');
  5. throw "Invalid number";
  6. }
  7. else if (Amount >1000000 || Amount < 1)
  8. {
  9. cin.clear();
  10. cin.ignore(500, '\n');
  11. throw "Please enter up to 1000000";
  12. }
Reputation Points: 28
Solved Threads: 0
Newbie Poster
icetux is offline Offline
11 posts
since Aug 2007
Sep 2nd, 2007
0

Re: Help with adding users

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.
Last edited by Ancient Dragon; Sep 2nd, 2007 at 11:28 pm.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: meta-library for compile time matrix operations
Next Thread in C++ Forum Timeline: please help me!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC