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
could you please help me?
this is my code
#include <iostream>
usingnamespace 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;
}
elseif(years>=4)
{
intRate = years*4/100;
}
elseif (years>=3)
{
intRate = years*3.5/100;
}
elseif (years>=2.5)
{
intRate = years*2.5/100;
}
elseif (years>=1)
{
intRate = years*2/100;
}
else (years<=1);
{
intRate = years*1.5/100;
}
interest = deposit + intRate;
cout<<"Your original deposit was $"<<deposit<<"\n";
cout<<"Your interest earned in"<<years "years is" <<intRate <<"\n";
cout<<"Your new balance is $"<<interest <<"\n";
system("pause");
return 0;
}
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 ==========
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.