Sunday, August 2, 2009

Im trying to write a C program that outputs a bank statement?

The user should be allowed to enter a begining balance and the transaction one at a time. When the transaction is a deposit, the user precedes the transaction with "D" and withdrawal with "W" and a check with "C" and should include the check number. The program should report all transactions and the final balance.

Im trying to write a C program that outputs a bank statement?
//This'll get you started:





#include %26lt;stdio.h%26gt;


#include %26lt;conio.h%26gt;


#include %26lt;stdlib.h%26gt;


#define MAX_ENTRIES 500 //enough for 500 entries





struct tagRecord{


char TransType; //...W, C, or D


float amount; //dollars and cents


}Record[MAX_ENTRIES];





int main()


{


int i;





//clear/init the Record database


for(i=0; i%26lt;MAX_ENTRIES; i++)


Record[i].TransType = 0;





printf("\nEnter Transaction Type: ");


Record[0].TransType = toupper(getch());





printf("\nEnter Amount: ");


scanf( "%f", %26amp;Record[0].amount);





for(i=0; Record[i].TransType; i++)


printf("Transaction Type: %c Amount: %.2f \n",


Record[i].TransType, Record[i].amount)





return 0;


}
Reply:Can you be a bit more specific with the part you are stuck on? Nobody here is going to do your assignment for you! You need to use scanf or a similar function to read the data in and perhaps an array of structures to store the data
Reply:get a variable to read the balance as an integer, and a variable to read the transaction. then program it to check what the first character is. after extracting the character, use an if statement or something similar (select case, *** loop, etc.). to make the output look better, code it so that the defining symbol (w for withdrawal, d for deposit, c### for check) is removed before recording it to the file. if you don't want to write to a file, store the transactions in an array after the program is done with them.


No comments:

Post a Comment