please help me with this...
i want to create a expense manager. my program is such that i enter new entry. but along with that, i also want to show the total expense. all the entries that i add, are stored in a text file.
is there any way to keep on changing the 'total expense' every time the program is executed????
can we keep on cumulating the individual expense every time an entry is made and display it in text file???
i am quite new to coding ...so i don't know what logic or command i can use for my problem..and it's not any of my school/college homewrk or something...so please help me solve my problem.
if you'll think i should change any part of my program so that i can get my desired output..then please do tell...can you'll help me ??? thanks for replying bluecoder an coder777
is there any way to keep on changing the 'total expense' every time the program is executed????
Although I did not get how you intend to do it you can use rand() to get a random value. To get different value at every program execution use srand() of course (otherwise the series of random number generated would be the same). http://www.cplusplus.com/reference/clibrary/cstdlib/srand/
what i wish to do is:
before 1st entry, the total expense/sum must be zero.
after 1st entry, the sum is total of 1st entry.
when 2nd entry is entered, the sum must become 1st entry+2nd entry.
on 3rd entry, the sum must include 1st, nd and 3rd...and so on...
because the program must be executed differently for ading a new entry everytime, where do i keep the cumulative sum everytime the program ends so that the new value of sum can be used next time the program is executed.
while working with files, how can i take data stored in a file as input for my variable???
is it possible???
if it is possible, then i store the data in a separate file and keep overwriting it using the data stored.
so the new file will always contain my total expense.
so if a .txt file contains just numbers, then can that number be stored in a variable the way data is stored into a variable while using "cin"???
#include<iostream>
#include<conio.h>
#include <string>
#include<fstream>
usingnamespace std;
int main()
{
string str_result ;
float sum =0 , value = 0 ;
char ch = 'Y';
ifstream file("account.txt");
while(getline(file , str_result))
{
sum = atof(str_result);
};
file.close();
do
{
cout<<"\n Enter the value of the amount ";
cin>>value ;
sum += value ;
cout<<"\n Do you want to continue ";
cin>>ch;
} while (ch != 'n');
ofstream ofile( test.txt );
ofile<<<sum;
ofile.close();
move( test.txt . account.txt ); //renaming the test.txt to account.txt
}
I have not checked this code please my apologies if there is any error .