@Rascal - you may find it useful to look at this related thread:
http://www.cplusplus.com/forum/beginner/93212/#msg500853
Meanwhile, I tried your code above and the program failed at line 24
|
in_stream >> accountNumber >> openingBalance >> transaction >> transactionAmount;
|
I think the reason is an uninitialised pointer at line 22:
char* transaction;
Actually, since the transaction is just a single character rather than a string, you don't need a pointer here, a simple char would do.
Around line 31 onwards should be contained in some sort of loop, in order to read and process each transaction. Again, I refer you to the other thread for an example.
Edit:
Your if statement has multiple issues.
a) comparing two c-strings would need the
strcmp()
function.
b) the "=" symbol is the assignment operator, it sets the variable on the left equal to the value of the expression on the right. When you use it in an if () condition, it will always be true, hence the
if is executed. The test for equaity is done using the "==" operator.
c) the
else is executed because there are missing braces { } around that part.