Need help with my simple interest program

Im taking a C++ class, which was offered online only and my professor is bad communication.

I need to:
Write a program which calculates the value of a fixed deposit at the time of maturity. Your program should be able to accept the following input from the user:
1. The deposit amount.
2. The period for deposit.

Use the following formula for interest.

Interest amount = (Amount Deposited * Annual %Interest Rate * Period of deposit in years)/100

Assume an annual interest rate of 10%.

I think I have everything if you guys can look over it. THE THING I NEED HELP ON IS HOW DO I GET THE 10 PERCENT TO ALWAYS BE IN THE RATE I THINK THATS WHAT THE PROFESSOR WANTS?

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
 #include<iostream>
using namespace std;

int main ()
{
		int p,r,t,i;
		
		cout<<"Enter Deposit Amount : ";
		
		cin>>p;
		
		cout<<"Enter Rate : ";
		
		cin>>r;

		cout<<"Enter Period of Deposit in years : ";
		
		cin>>t;
		
		i=(p*r*t)/100;
		
	cout<<"Simple intrest is :"<<i<<endl;
	


		return 0;
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<iostream>
using namespace std;

int main ()
{
    int p, t;
    float i;
    const float rate = .10;

    cout << "Enter Deposit Amount: ";
    cin >> p;
    cout << "Enter Period of Deposit in years: ";
    cin >> t;

    i = (p * rate * t) / 100;

    cout << "Simple interest is: " << i << endl;

	return 0;
}
Uhh wouldn't you just not ask the user for a rate ? Or, for whatever reason, you want to ask the user for a rate, but whatever they put it doesn't matter because you have it always at 10%. In this case, I would do this:

const double rate = 0.1;

The const makes sure that whatever happens, rate is always going to be the value 0.1. I also put double instead of int because I think int is just for whole numbers, while double can be used for like 4.5 0.3 etc, and 10% is 0.10.

I am a beginner too so if this is wrong please correct me.

-ilovejapanesegirls
I think @popeye is correct, if you guys saw the post I put i removed it because i forgot the /100

So thank you pop eye

Topic archived. No new replies allowed.