Pages

Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Monday, December 31, 2012

Torn City bank calculator [TCBasic]

Situation : There is a bank that we can put out money to get profit.
In this bank there are 5 period mode.
1. 1 week
2. 2 week
3. 1 month
4. 2 month
5. 3 month

for example, we choose mode one. so we only can withdraw the money after 1 week mature time.

Different period mode will use different interest rate. Table below shows about the formulas for the interest rate.

Interest Rate Formulas:.


0 Merits Each Bank Merit
1 Week Base Rate* + 0.10
2 Weeks Base x 2.3 + 0.23
1 Month Base x 5 + 0.50
2 Months Base x 11 + 1.10
3 Months Base x 16 + 1.60
* (1 week, 0 merits interest rate- eg 1.07% in the current table above)

as you can see, the interest rate is depend on the period mode, base value and bank merit.
base value is the initial interest rate that would varies depend on the economy. for our case, we can consider it 0.95.
bank merit is the bank upgrade that we can invest. actually, this formula is for a game call Torncity, the formula and the detail for the bank can be read here

so our main topic is about the calculator. this calculator i create it using C++ programming. i create it using Borland C++ 5.02.

here is the source code.



Source

Sunday, February 27, 2011

File operation in C programming(text file method)

There are two type file operation. One is using text file method and another one using binary file method. The method is for text file method.

First step is to define


FILE *
example :
FILE *ifile;
FILE *book;

Then to open a text file in c programming

function : fopen()
format : fopen("filename",mode);
mode:
"r" = read only
"w" = write only(start from beginning file-replace all previous data)
"a" = write only(start at end file- if got data in the data, it will not be replace)
"r+" = open to update the data(read and write)
"w+"= open to update the data(create,read and write)

example
fopen("book.txt","w");
fopen("new/inputfile.text","r");

note: only one mode in one fopen statement. cannot use"rw". can open a file to write and to read but once open to read must close it first to reopen for write operation.

To write to the text data

function : fprintf()
format : fprintf(FILE *,"",);
example:
fprintf(FILE *ifile, "%d\n", int data);
fprintf(FILE *book,"%c\n", char books);

To read from text file

function: fscanf()
format: fscanf(FILE *,"",);
example:
fscanf(FILE *ifile, "%d\n", int data);
fscanf(FILE *book,"%c\n", char books);

To close the text file

function : fclose()
format: fclose(FILE *);
example:
fclose(ifile);
fclose(book);

Full sequence in a main function

void main()
{
FILE *ifile;
FILE *book;
char books[10];
int data;

fopen("/new/inputfile.text","r");
fopen("book.txt","w");

fscanf(ifile, "%d\n",data);

fprintf(book,"%c\n",books);

fclose(ifile);
fclose(book);

return;
}