Part of my balance program: here is the withdraw function. There is a logging feature in it. Whenever the logging feature runs I get "failed debug assertions" and a big 'n happy illegal operation. I think it has to do with array overbounds, but I cannot find what. Variables balance, amount, and TempBalance are doubles. Here's the code for the function (The problem starts after the "LOGGING" comment.)
Code:
double withdraw(double amount,bool UsedInCreation = false)//RETURN VALUES: 0.00-INFINITY = Success, -2 = FAIL(not enough money), -1 = FAIL(other error)
{
double TempBalance = balance;
char* LogMessage = new char[1];
char* TextBuffer = new char[35];
if(amount == -1)
balance = balance - balance;
else if(amount != -1 && amount < 0)
return 0;
else if(amount > 0)
TempBalance = TempBalance - amount;
if(TempBalance < 0)
return -2;
else
{
//LOGGING
if(UsedInCreation == false)
{
time_t TimeVar = time(NULL);
time_t* MyTime = &TimeVar;
strcat(LogMessage,ctime(MyTime));
strcat(LogMessage," | WITHDRAWL | ");//NOTE: 11 chars between bars
sprintf(TextBuffer,"%f",balance);
CutToTwo(TextBuffer);
strcat(LogMessage,TextBuffer);
strcat(LogMessage," - ");
sprintf(TextBuffer,"%f",amount);
CutToTwo(TextBuffer);
strcat(LogMessage,TextBuffer);
strcat(LogMessage," = ");
sprintf(TextBuffer,"%f",TempBalance);
CutToTwo(TextBuffer);
strcat(LogMessage,TextBuffer);
strcat(LogMessage,"\n");
//cout << LogMessage;
}
else
{
}
//END LOGGING
balance = TempBalance;
}
return balance;
}