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
could you please help me?
this is my code
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
38
39
40
41
42
43
44
45
46
#include <iostream> 
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 $"<<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 ==========


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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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.