Hi guys, relatively new here.
Decided to pick up C++ after a long time, and I'm still in novice mode.
I'm studying from myself, through books, and my first attempt with the tutorial is a financial program, the user gives base capital, interest, and the amount of years.
The program then calculates your end capital (savings) using the well known formula:
Basecapital * (Interest ^ Years)
Now I run into a couple of problems, first thing is the interest isn't properly working.
If someone enters 5, I want to calculate 1.05 from that, I did that using this line:
realinterest = (rawinterest + 100) *0,01;
Enter 5? Should be 5+100, multiplied by 0,01 which would make 1.05.
As a test I cout the real interest and it returns zero.
So my decimals aren't existing, 1.05 turns magically into zero.
Secondly, the compilers keeps giving me messages: Illegal operand: left type has float.
I think it's telling me that the float type is not usable here, but to work with decimals I can't use int right?
Could someone provide assistance? Thanks!
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 47 48 49 50 51 52 53 54 55
|
// first application in C++
#include <iostream>
#include <string>
using namespace std;
int main ()
{
int age; //initializing variables and strings
int agemom;
int agetotal;
string job;
int startcapital;
float rawinterest;
float realinterest;
float years;
int endcapital;
|
//THIS WORKS
cout << "Hello World" << endl; //printing text
cout << "This program is written in C++" << endl;
cout << "Enter your age" << endl;
cin >> age; //input of age
cout << "So you are " << age << " years old." << endl;
cout << "How old is your mom?" << endl;
cin >> agemom; //process
agetotal = age + agemom;
cout << "Whoa, combined you and your mom are " << agetotal << " old." << endl; //output
cout << "Where do you work?" << endl;
cin >> job;
cout << "It must be really difficult working at " << job << endl;
--------------------------------------------------------------------------------------------------------------
//THIS PART DOESN'T WORK
cout << "This program can also calculate your future savings" << endl;
cout << "Enter the amount of capital to begin with" << endl;
cin >> startcapital;
cout << "Enter the annual percentage of interest" << endl;
cin >> rawinterest;
realinterest = (rawinterest + 100) *0,01;
cout << "Enter the amount of years you're saving money" << endl;
cin >> years;
cout << realinterest;
endcapital = (startcapital) * (realinterest ^ years);
cout << "Okay, your " << startcapital << " will be worth " << endcapital << " after " << years << " years.";
system("pause"); //pause
return 0;
}
----------------------------------------------------------------------------------------------------------------- |