Why does this not display 2% when it outputs all the answers. It does the calculation of 2% fine but doesn't display "interest rate: 2%"
#include <iostream>
using namespace std;
int main(){
int accBalance = 0;//change keypoint name , initialize value are important
float interestPaid = 0;
float interestRate = 0;
float totalBalance = 0;
You can't use the == operator on floats. How floats are handled and truncated vary with computer and compiler. It is highly unlikely that the value of interestRate will ever equal exactly 0.02, because floating point variables are always calculated to seven significant digits It will actually be something like "0.0200001." You can never know exactly what the margin of error will be on these calculations, so a rule of thumb is to never use the equality operator on floats/doubles.
A way around this would be to output the variable directly.
Okay thanks helped a lot. I need to amend it now so that tax can be deducted from interest. the programs needs to give an option at the start if to tax the interest. Tax rate should be %20. the output needs to be changed so that it shows tax deducted. this is what i have done so far.
#include <iostream>
using namespace std;
int main(){
int accBalance = 0;//change keypoint name , initialize value are important
float interestPaid = 0;
float interestRate = 0;
float totalBalance = 0;
int yestax
int notax