I just started learning loops and stuff and I am in need of help! I have this ATM program that is all messed up and I have no idea how to fix it. The program asks for first name, last name, account number, statement balance, outstanding deposits and outstanding withdrawls. Then it calculates and shows the result. Then it asks if they would rather print out the screen, or print to a textfile (print to textfile is default for this). If it helps, I use dev C++. Anyone please look at my code and help me out! Thanks a whole bunch.
Code:
//This program written by Dan Kemper
//This program will balance your checkbook and print the results to a textfile named "checkbook.txt" or print the scrren to your printer
//Suggestions and other comments can be sent to my email: [email protected]
# include <iostream.h>
# include <fstream.h>
# include <iomanip.h>
# include <conio.h>
int main ()
{
//Declares variables
char FirstName[20];
char LastName[30];
char Account[9];
int PrintStatement;
float Balance;
float Deposits;
float Withdrawls;
float NewBalance;
//Makes Textfile
ofstream outfile ("checkbook.txt");
//Outputs to screen
cout << " AAA TTTTTTTTTTTTTTT MMMMM MMMMM\n";
cout << " AAAAA TTTTTTTTTTTTTTT MMMMMM MMMMMM\n";
cout << " AAA AAA TTTTTT MMM MMM MMM MMM\n";
cout << " AAA AAA TTTTTT MMM MMM MMM MMM\n";
cout << " AAAAAAAAAAA TTTTTT MMM MMM MMM MMM\n";
cout << " AAAAAAAAAAAAA TTTTTT MMM MMM MMM MMM\n";
cout << " AAA AAA TTTTTT MMM MMM MMM MMM\n";
cout << "AAA AAA TTTTTT MMM MMMMM MMM\n";
system("PAUSE");
cout << "\n\nThis program balances your checkbook.\n\n";
cout << "First Name: ";
//Asks user for input
cin.get(FirstName, 20);
cin.ignore(80, '\n');
cout << "Last Name: ";
cin.get(LastName, 30);
cin.ignore(80, '\n');
cout << "Account number: ";
cin.get(Account, 9);
cin.ignore(80, '\n');
cout << "\n\nStatement balance: ";
cin >> Balance;
cout << "\nOutstanding deposits: ";
cin >> Deposits;
cout << "\nOutstanding withdrawls: ";
cin >> Withdrawls;
//Conversions
NewBalance = Balance + Deposits - Withdrawls;
//Output Results
cout << "\nNew balance: ";
cout << setiosflags (ios::fixed) << setprecision(2) << NewBalance;
cout << "\n\nPrint? (Y/N)\n";
cin >> PrintStatement;
do
{
while (PrintStatement=='y' || PrintStatement=='Y')
{
system("PRINT");
cout << "Thank You!";
getch ();
return 0;
}
else
{
cout << "Thank You! You may see your statement in a textfile named 'checkbook.txt'.";
}
}
//Prints to Textfile
outfile << "Name: " << FirstName << " " << LastName << "\n";
outfile << "Account Number: " << Account << "\n";
outfile << "Statement Balance: " << Balance << "\n";
outfile << "Outstanding Deposits: " << Deposits << "\n";
outfile << "Outstanding Withdrawls: " << Withdrawls << "\n";
outfile << "New Balance: " << setiosflags (ios::fixed) << setprecision(2) << NewBalance;
//Stops program until button is pressed
getch();
return 0;
}