/*
    lscompounder is a basic stock/financial helper suite.
    Copyright (C) 2009  sterling pickens

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


double compseriesfunc(double principle1, char* rates)
{
	int i;
	//double principle1;
	double rate1;
	double principle2;
	double last;
        const char *token;
        const char *line;
        const char *search = " ";

	//token = strtok(rates, search);

	//principle1 = atof(argv[1]);
	principle2 = principle1;

	//printf("%s\n", token);
//token = strtok(NULL, search);
//printf("%s\n", token);



	for(token = strtok(rates, search); token != NULL; token = strtok(NULL, search) )
	{
		//token = strtok(NULL, search);
		rate1 = atof(token);
		//token = strtok(NULL, search);
		last = principle2;
		principle2 =  principle2 * ((100+rate1)/100);
		last = principle2 - last;
	}

/*


	for(i=2;i<argc;i++)
	{

		rate1 = atof(argv[i]);
		last = principle2;
		principle2 =  principle2 * ((100+rate1)/100);
		last = principle2 - last;
		printf("trade %d: \t%lf%% \t$%lf \t$%lf\n", i-1, rate1, principle2, last);
	
	}

*/

	last = principle2 - principle1;
	rate1 = ((principle2 / principle1)-1) * 100;
	//printf("\n\tending amount: %lf%% $%lf $%lf\n\n", rate1, principle2, last);
	
	return principle2;
}
