Hello!
This is my first thread on here but I hope to be posting a lot more because C++ has become very interesting and I have many projects in mind.
Now on to my question....
I am creating a simple console app (as my first project) that is just a simple cash accounting program. It uses multiple files to store numerical currency data which can be appended or read as needed. Everything seems to work fine BUT when I try to multiply a numerical variable by a decimal number, it just returns a 0.
The example I will show is for when a user will be depositing pennies into the account. The program asks for number of pennies, takes the input and adds it to whatever value was stored in the .dat file, replaces the old amount with new, and is supposed to display how much was added to the account. (This is where the issue comes up, everything else works perfectly, only the multiplying is off)
And I should mention that when a whole number is used, like 2, the program multiplies it correctly, only decimal numbers.
I understand its a bit messy but I am just trying to get it to work properly before cleaning it up :P
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
|
char depopen()
{
int penum;
int pendepsta;
int pendepfin;
int pendepcalc;
if(system("CLS"));
cout<<"\n";
cout<<" Enter Number of Pennies to Deposit\n\n";
cout<<" Number of Pennies: ";
cin>> penum; //Where # of pennies is entered
cin.ignore();
ifstream apenfil ("pen.dat");
apenfil>> pendepsta; //opening file to retrieve numerical variable
apenfil.close();
pendepfin=(penum+pendepsta); //<<Formula works correctly, where vars are added to form new
ofstream bpenfil ("pen.dat", ios::trunc);
bpenfil<< pendepfin; //insertion of new numerical value
bpenfil.close();
pendepcalc = (0.01* penum); //Where I want numerical input to be multiplied by .01
cout<<"\n\n Added $";
cout<< pendepcalc; // where I would like amount added to be displayed
cout<<" to your Account.\n";
cin.get();
depo();
return (0);
}
|
Thanks for any help! I just could not seem to find an answer online so maybe I am neglecting some simple C++ concept but idk... :P