| | |
Need help with my C++
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Aug 2007
Posts: 11
Reputation:
Solved Threads: 0
Hey, I am a total newbie I need help finding errors in my code.
C++ Syntax (Toggle Plain Text)
// Week 4 Individual Assignment // Calculate the monthly payment User input. // 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; double Term; double Interest; double MnthPayment; double rPayments; double newAmount; double loanPrinciple; double loanAmount; double cMnthInterest; double MnthAmount; int m = 0; int main() { double mInterest; double mTerm; bool indic=false; char repeat; do { //Data Entry cout << "Loan amount: "; cin >> Amount; cout << endl << "Interest rate: "; cin >> Interest; cout << endl << "Term of the loan in years: "; cin >> Term; //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 <<"Would you like to calculate another loan?" << endl <<"Please enter Y to repeat or any other key to exit: "; cin >> repeat; cout << endl; 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; //assign user input value to control variable if (repeat == 'y' || repeat == 'Y') indic = true; else { cout << endl <<"Thank you for using the Mortgage Calculator" << endl << endl; indic = false; } }while(indic == true); return 0; } // end
Last edited by icetux; Aug 28th, 2007 at 9:10 am.
•
•
Join Date: Aug 2007
Posts: 11
Reputation:
Solved Threads: 0
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.
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.
C++ Syntax (Toggle Plain Text)
// Calculate the monthly payment user input. // 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; double Term; double Interest; double MnthPayment; double rPayments; double newAmount; double loanPrinciple; double loanAmount; double cMnthInterest; double MnthAmount; int m = 0; int main() { double mInterest; double mTerm; bool indic=false; char repeat; do { //Data Entry cout << "Loan amount: "; cin >> Amount; cout << endl << "Interest rate: "; cin >> Interest; cout << endl << "Term of the loan in years: "; cin >> Term; //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 <<"Would you like to calculate another loan?" << endl <<"Please enter Y to repeat or any other key to exit: "; cin >> repeat; cout << endl; 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; //assign user input value to control variable if (repeat == 'y' || repeat == 'Y') indic = true; else { cout << endl <<"Thank you for using the Mortgage Calculator"<< endl << endl; indic = false; } } }while(indic == true); return 0; // end
Last edited by icetux; Aug 28th, 2007 at 10:45 pm.
Basic attempt with a beautifier:
C++ Syntax (Toggle Plain Text)
// Calculate the monthly payment user input. // 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; double Term; double Interest; double MnthPayment; double rPayments; double newAmount; double loanPrinciple; double loanAmount; double cMnthInterest; double MnthAmount; int m = 0; int main() { double mInterest; double mTerm; bool indic=false; char repeat; do { //Data Entry cout << "Loan amount: "; cin >> Amount; cout << endl << "Interest rate: "; cin >> Interest; cout << endl << "Term of the loan in years: "; cin >> Term; //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 <<"Would you like to calculate another loan?" << endl <<"Please enter Y to repeat or any other key to exit: "; cin >> repeat; cout << endl; 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; //assign user input value to control variable if ( repeat == 'y' || repeat == 'Y' ) indic = true; else { cout << endl <<"Thank you for using the Mortgage Calculator"<< endl << endl; indic = false; } } }while(indic == true); return 0; // 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
![]() |
Other Threads in the C++ Forum
- Previous Thread: Aquarium Program- Help setting system time etc...
- Next Thread: How to clear a string
Views: 756 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






