I am trying to add two floats in a for loop and its telling me ‘+’ has no affect. I am attempting to make it parse through each incrememnt (.25) of the two ranges (begrate and endrate) (1 and 2) and 1+.25 is not working correctly and I get an infinite loop
float begrate,endrate,inc,year=0;
cout << "Monthly Payment Factors used in Compute Monthly Payments!" << endl;
cout << "Enter Interest Rate Range and Increment" << endl;
cout << "Enter the Beginning of the Interest Range: ";
cin >> begrate;
cout << "Enter the Ending of the Interest Range: ";
cin >> endrate;
cout << "Enter the Increment of the Interest Range: ";
cin >> inc;
cout << "Enter the Year Range in Years: ";
cin >> year;
cout << endl;
for (float i=1;i<year;i++){
cout << "Year: " << " ";
for(begrate;begrate<endrate;begrate+inc){
cout << "Test " << begrate << endl;
}
}
system("pause");
return 0;
You could use += instead of +, as this will set
begratetobegrate+inc. The better solution would be to have a temporary loop variable that starts equal to begrate then increment it.