Calculation

I am trying to compile a program that will calculate the value of a fixed deposit at the time of maturity. It lets me input the amount of deposit and the number of year. After I enter in the years and hit enter the program shuts down but does not return the amount of deposit at the time of maturity. This what I have so far, any help will be greatly appreciated.

#include "stdafx.h"
#include <iostream>

int main()

{
using namespace std;

int deposit;
int years;
int amount();
amount = ( deposit * .10 * years )/ 100;

cout << "Please enter deposit: ";
cin >> deposit ;
cout << endl;
cout << "Enter number of years: ";
cin >> years ;
cout << endl;
cout << "Once matured balance is " << amount << ".";
cout << endl;
return 0;

}

As far as the console shutting down, check out this thread:
http://www.cplusplus.com/forum/beginner/1988/

Your program still has troubles, you calculate amount before entering anything into deposit or years.
add cin.get(); before the return statement! if the problem persists, add cin.ignore(); to clear the buffer before cin.get();

Also, this is the fixed code, with reference with what LowestOne said:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include "stdafx.h"

int main()
{
    using namespace std;

    int deposit;
    int years;
    double amount;

    cout << "Please enter deposit: ";
    cin >> deposit ;
    cout << endl;
    cout << "Enter number of years: ";
    cin >> years ;
    cout << endl;
    amount = ( deposit * .10 * years )/ 100;
    cout << "Once matured balance is " << amount << ".";
    cout << endl;
    cin.ignore();
    cin.get();
    return 0;
}


Hope it HELPS!!!
Last edited on
Thank you so much. It works now.
Topic archived. No new replies allowed.