Need help with my C++

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2007
Posts: 11
Reputation: icetux is an unknown quantity at this point 
Solved Threads: 0
icetux icetux is offline Offline
Newbie Poster

Need help with my C++

 
0
  #1
Aug 28th, 2007
Hey, I am a total newbie I need help finding errors in my code.



  1.  
  2. // Week 4 Individual Assignment
  3. // Calculate the monthly payment User input.
  4.  
  5. // Include header files
  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. //Namespaces
  17. using namespace std;
  18.  
  19.  
  20.  
  21. //Declare and initialize variables
  22. double Amount;
  23. double Term;
  24. double Interest;
  25. double MnthPayment;
  26. double rPayments;
  27. double newAmount;
  28. double loanPrinciple;
  29. double loanAmount;
  30. double cMnthInterest;
  31. double MnthAmount;
  32. int m = 0;
  33.  
  34.  
  35. int main()
  36. {
  37. double mInterest;
  38. double mTerm;
  39.  
  40.  
  41. bool indic=false;
  42. char repeat;
  43.  
  44.  
  45. do
  46. {
  47. //Data Entry
  48. cout << "Loan amount: ";
  49. cin >> Amount;
  50. cout << endl << "Interest rate: ";
  51. cin >> Interest;
  52. cout << endl << "Term of the loan in years: ";
  53. cin >> Term;
  54. //cout << endl<< Fetching <<endl << endl;
  55.  
  56. mInterest = Interest/(12*100);
  57. mTerm = Term * 12;
  58.  
  59.  
  60. // Calculate the payment
  61. MnthPayment = (Amount * pow((1 + mInterest), mTerm)* mInterest)/(pow((1 + mInterest),mTerm)-1.0);
  62.  
  63. // Print out for calculations
  64.  
  65. cout << "The mortgage payment:$" << MnthPayment <<"\n";
  66.  
  67. //prompt for repeat
  68. cout <<"Would you like to calculate another loan?" << endl
  69. <<"Please enter Y to repeat or any other key to exit: ";
  70. cin >> repeat;
  71. cout << endl;
  72.  
  73. while (m < rPayments)
  74.  
  75. //Math to figure out values for table
  76. MnthPayment = Interest * mInterest;
  77. Amount = MnthPayment - cMnthInterest;
  78. newAmount = loanPrinciple - MnthAmount;
  79. loanAmount = newAmount;
  80.  
  81. // Controling the size length of text
  82. if(m % 12 == 0)
  83. {
  84. cout<<"Enter to continue";
  85. cin.get();
  86. cout<<endl<<endl;
  87. cout<<setw(18)<<"Interest";
  88. cout<<setw(21)<<"New Principle"<<endl<<endl;
  89. }
  90.  
  91. m++;
  92.  
  93. //Table
  94. cout<<setw(4)<<m;
  95. cout<<setw(20)<<setiosflags(ios:fixed)<<setprecision(2)<<cMnthInterest<<setw(22)<<loanAmount<<endl;
  96.  
  97.  
  98. //assign user input value to control variable
  99. if (repeat == 'y' || repeat == 'Y') indic = true;
  100. else
  101. {
  102. cout << endl <<"Thank you for using the Mortgage Calculator"
  103. << endl << endl;
  104. indic = false;
  105. }
  106.  
  107.  
  108. }while(indic == true);
  109.  
  110. return 0;
  111.  
  112. } // end
Last edited by icetux; Aug 28th, 2007 at 9:10 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 322
Reputation: Hamrick will become famous soon enough Hamrick will become famous soon enough 
Solved Threads: 33
Hamrick's Avatar
Hamrick Hamrick is offline Offline
Posting Whiz

Re: Need help with my C++

 
0
  #2
Aug 28th, 2007
In setiosflags(ios:fixed) you only used one : instead of two for name resolution. It should be setiosflags(ios::fixed).
The truth does not change according to our ability to stomach it.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 11
Reputation: icetux is an unknown quantity at this point 
Solved Threads: 0
icetux icetux is offline Offline
Newbie Poster

Re: Need help with my C++

 
0
  #3
Aug 28th, 2007
Thank you that did help. I now have to find out where I left off a }

fatal error C1075: end of file found before the left brace '{'
Edit/Delete Message
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 11
Reputation: icetux is an unknown quantity at this point 
Solved Threads: 0
icetux icetux is offline Offline
Newbie Poster

Re: Need help with my C++

 
0
  #4
Aug 28th, 2007
I am getting these errors, I just not finding what I am missing.


error C2143: syntax error : missing ';' before ']'
error C2059: syntax error : '}'
error C2059: syntax error : 'while'
error C2059: syntax error : 'return' I am getting these errors.

  1.  
  2. // Calculate the monthly payment user input.
  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. double 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.  
  35.  
  36. int main()
  37. {
  38. double mInterest;
  39. double mTerm;
  40.  
  41.  
  42. bool indic=false;
  43. char repeat;
  44.  
  45.  
  46. do
  47. {
  48. //Data Entry
  49. cout << "Loan amount: ";
  50. cin >> Amount;
  51. cout << endl << "Interest rate: ";
  52. cin >> Interest;
  53. cout << endl << "Term of the loan in years: ";
  54. cin >> Term;
  55. //cout << endl<< Fetching <<endl << endl;
  56.  
  57. mInterest = Interest/(12*100);
  58. mTerm = Term * 12;
  59.  
  60.  
  61. // Calculate the payment
  62. MnthPayment = (Amount * pow((1 + mInterest), mTerm)* mInterest)/(pow((1 + mInterest),mTerm)-1.0);
  63.  
  64. // Print out for calculations
  65.  
  66. cout << "The mortgage payment:$" << MnthPayment <<"\n";
  67.  
  68. ] //prompt for repeat
  69. cout <<"Would you like to calculate another loan?" << endl
  70. <<"Please enter Y to repeat or any other key to exit: ";
  71. cin >> repeat;
  72. cout << endl;
  73.  
  74. while (m < rPayments)
  75.  
  76. //Math to figure out values for table
  77. MnthPayment = Interest * mInterest;
  78. Amount = MnthPayment - cMnthInterest;
  79. newAmount = loanPrinciple - MnthAmount;
  80. loanAmount = newAmount;
  81.  
  82. // Controling the size length of text
  83. if(m % 12 == 0)
  84. {
  85. cout<<"Enter to continue";
  86. cin.get();
  87. cout<<endl<<endl;
  88. cout<<setw(18)<<"Interest";
  89. cout<<setw(21)<<"New Principle"<<endl<<endl;
  90. }
  91.  
  92. m++;
  93.  
  94. //Table
  95. cout<<setw(4)<<m;
  96. cout<<setw(20)<<setiosflags(ios::fixed)<<setprecision(2)<<cMnthInterest<<setw(22)<<loanAmount<<endl;
  97.  
  98.  
  99. //assign user input value to control variable
  100. if (repeat == 'y' || repeat == 'Y') indic = true;
  101. else
  102. {
  103. cout << endl <<"Thank you for using the Mortgage Calculator"<< endl << endl;
  104.  
  105. indic = false;
  106. }
  107.  
  108. }
  109.  
  110. }while(indic == true);
  111.  
  112. return 0;
  113.  
  114. // end
Last edited by icetux; Aug 28th, 2007 at 10:45 pm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,461
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 254
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Need help with my C++

 
0
  #5
Aug 28th, 2007
Basic attempt with a beautifier:
  1. // Calculate the monthly payment user input.
  2.  
  3. // Include header files
  4.  
  5.  
  6. #include <iostream>
  7. #include <iomanip>
  8. #include <math.h>
  9.  
  10. using std::cout;
  11. using std::endl;
  12. using std::cin;
  13. using std::ios;
  14.  
  15.  
  16. //Namespaces
  17. using namespace std;
  18.  
  19.  
  20.  
  21. //Declare and initialize variables
  22. double Amount;
  23. double Term;
  24. double Interest;
  25. double MnthPayment;
  26. double rPayments;
  27. double newAmount;
  28. double loanPrinciple;
  29. double loanAmount;
  30. double cMnthInterest;
  31. double MnthAmount;
  32. int m = 0;
  33.  
  34.  
  35. int main()
  36. {
  37. double mInterest;
  38. double mTerm;
  39.  
  40.  
  41. bool indic=false;
  42. char repeat;
  43.  
  44.  
  45. do
  46. {
  47. //Data Entry
  48. cout << "Loan amount: ";
  49. cin >> Amount;
  50. cout << endl << "Interest rate: ";
  51. cin >> Interest;
  52. cout << endl << "Term of the loan in years: ";
  53. cin >> Term;
  54. //cout << endl<< Fetching <<endl << endl;
  55.  
  56. mInterest = Interest/(12*100);
  57. mTerm = Term * 12;
  58.  
  59.  
  60. // Calculate the payment
  61. MnthPayment = (Amount * pow((1 + mInterest), mTerm)* mInterest)/(pow((1 + mInterest),mTerm)-1.0);
  62.  
  63. // Print out for calculations
  64.  
  65. cout << "The mortgage payment:$" << MnthPayment <<"\n";
  66.  
  67. ] //prompt for repeat
  68. cout <<"Would you like to calculate another loan?" << endl
  69. <<"Please enter Y to repeat or any other key to exit: ";
  70. cin >> repeat;
  71. cout << endl;
  72.  
  73. while ( m < rPayments )
  74.  
  75. //Math to figure out values for table
  76. MnthPayment = Interest * mInterest;
  77. Amount = MnthPayment - cMnthInterest;
  78. newAmount = loanPrinciple - MnthAmount;
  79. loanAmount = newAmount;
  80.  
  81. // Controling the size length of text
  82. if ( m % 12 == 0 )
  83. {
  84. cout<<"Enter to continue";
  85. cin.get();
  86. cout<<endl<<endl;
  87. cout<<setw(18)<<"Interest";
  88. cout<<setw(21)<<"New Principle"<<endl<<endl;
  89. }
  90.  
  91. m++;
  92.  
  93. //Table
  94. cout<<setw(4)<<m;
  95. cout<<setw(20)<<setiosflags(ios::fixed)<<setprecision(2)<<cMnthInterest<<setw(22)<<loanAmount<<endl;
  96.  
  97.  
  98. //assign user input value to control variable
  99. if ( repeat == 'y' || repeat == 'Y' ) indic = true;
  100. else
  101. {
  102. cout << endl <<"Thank you for using the Mortgage Calculator"<< endl << endl;
  103.  
  104. indic = false;
  105. }
  106.  
  107. }
  108.  
  109. }while(indic == true);
  110.  
  111. return 0;
  112.  
  113. // end
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 11
Reputation: icetux is an unknown quantity at this point 
Solved Threads: 0
icetux icetux is offline Offline
Newbie Poster

Re: Need help with my C++

 
0
  #6
Aug 29th, 2007
I just fixed my errors I just need to work on the logic.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum


Views: 756 | Replies: 5
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC