Below is the code you posted.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
using namespace std;
int main(void){
int n = 30 * 12; // totalNumberOfPayments;
double yrp, P, mrd, numerator, denominator, answer, estimate;
cout << "Enter the yearly interest rate. Ex: for 4.5% enter 4.5 ";
cin >> yrp;
cout << "Enter the loan amount: Ex: 500000 ";
cin >> P;
cout << "Enter the monthly payment you think you can make Ex: 1000 ";
cin >> estimate;
mrd = (yrp / 12) / 100.0;
numerator = P*mrd;
denominator = 1.0 - (1.0 / pow(1.0 + mrd, double(n)));
answer = numerator / denominator;
if (answer >= estimate - 250 !answer <= estimate + 250)
cout << "The monthly payment of $ " << fixed << setprecision(2) << answer;
cout << " may be a tight squeeze\n";
}
else if (answer > estimate - 250)
cout << "You can easily afford the monthly payment of $"
<< fixed << setprecision(2) << answer << endl;
otherwise
cout << "You probably cannot afford the monthly payment of $"
<< fixed << setprecision(2) << answer << endl;
return 0;
}
|
The following are the syntax error:
Error 1 error C2059: syntax error : 'else' Line: 29
Error 2 error C2146: syntax error : missing ';' before identifier 'cout' Line:33
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int Line:33
Error 4 error C2143: syntax error : missing ';' before '<<' Line:33
Error 5 error C2059: syntax error : 'return' Line: 36
Error 6 error C2059: syntax error : '}' Line: 37
Error 7 error C2143: syntax error : missing ';' before '}' Line: 37
Some notes...
On line 25, you are already tracking what you need.
Take a look at line 28. The closing bracket that you placed there, it is for the main function.
Therefore, you would get a syntax error: 'else'
Take a look at line 32. Is 'otherwise' a variable? If so, what is the type(i.e. int, double char...)?
Take a look at line 37. You have a closing bracket without an opening bracket.
Below is an example code of what I mean by fixing those syntax errors.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
using namespace std;
int main () /*(void)*/{ // http://en.cppreference.com/w/cpp/language/main_function
int n = 30 * 12; // totalNumberOfPayments;
double yrp, P, mrd, numerator, denominator, answer, estimate;
cout << "Enter the yearly interest rate. Ex: for 4.5% enter 4.5 ";
cin >> yrp;
cout << "Enter the loan amount: Ex: 500000 ";
cin >> P;
cout << "Enter the monthly payment you think you can make Ex: 1000 ";
cin >> estimate;
mrd = (yrp / 12) / 100.0;
numerator = P*mrd;
denominator = 1.0 - (1.0 / pow(1.0 + mrd, double(n)));
answer = numerator / denominator;
if (answer >= estimate - 250 || answer <= estimate + 250){// You sre tracking. Also, add an opening bracket.
cout << "The monthly payment of $ " << fixed << setprecision(2) << answer;
cout << " may be a tight squeeze\n";
}
else if (answer > estimate - 250)
cout << "You can easily afford the monthly payment of $"
<< fixed << setprecision(2) << answer << endl;
//otherwise . No clue why is otherwise is here.
cout << "You probably cannot afford the monthly payment of $"
<< fixed << setprecision(2) << answer << endl;
return 0;
}
|