### deposit with interest program

The program is suppose to accepts an amount of money on deposit and a number of years it has been on deposit(years can have decimals). It will determine the interest to be paid on the deposit based on the following schedule

Im having a problem getting this program to run
this is my code
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546`` ``````#include using namespace std; int main() { cout<<"Deposits with Interest Program"; float intRate; float deposit=0; float years=0; float interest = 0; cout<<"Please enter the amount deposited today: "; cin>> deposit ; cout<<"Please enter the number of years it has been on deposit: "; cin>> years; if(years >=5) { intRate = years*4.5/100; } else if(years>=4) { intRate = years*4/100; } else if (years>=3) { intRate = years*3.5/100; } else if (years>=2.5) { intRate = years*2.5/100; } else if (years>=1) { intRate = years*2/100; } else (years<=1); { intRate = years*1.5/100; } interest = deposit + intRate; cout<<"Your original deposit was \$"<

 ```1>------ Build started: Project: Money, Configuration: Debug Win32 ------ 1> deposit.cpp 1>f:\deposit.cpp(19): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data 1>f:\deposit.cpp(27): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data 1>f:\deposit.cpp(31): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data 1>f:\deposit.cpp(39): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data 1>f:\deposit.cpp(42): error C2143: syntax error : missing ';' before '<<' 1>f:\deposit.cpp(42): error C2143: syntax error : missing ';' before '<<' 1>f:\deposit.cpp(43): error C2143: syntax error : missing ';' before '<<' 1>f:\deposit.cpp(43): error C2296: '<<' : illegal, left operand has type 'const char [9]' 1>f:\deposit.cpp(43): error C2297: '<<' : illegal, right operand has type 'float' 1>f:\deposit.cpp(43): error C2143: syntax error : missing ';' before '<<' 1>f:\deposit.cpp(44): error C2143: syntax error : missing ';' before '<<' 1>f:\deposit.cpp(44): error C2143: syntax error : missing ';' before '<<' ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== ```

Last edited on
Take out the (years<=1); on line 35 and add an extra << on line 41. Else statements can't have a condition, only else if's.

The warnings are not errors and are just warning you because doubles are larger than floats and so if you had numbers with many decimal places some of them can be truncated when converting to a float.
Last edited on
Need to correct some of the statements.

 ``1234567891011121314151617181920212223`` ``````if(years >=5) { intRate = years*4.5/100; } else if(years>=4) //if(years>=4 || years<5) { intRate = years*4/100; } else if (years>=3) //correct { intRate = years*3.5/100; } else if (years>=2.5) //correct { intRate = years*2.5/100; } else if (years>=1) //correct intRate = years*2/100; } else (years<=1); { intRate = years*1.5/100; }``````
Topic archived. No new replies allowed.