In CS2 we had to write a basic bank program with classes. I wrote the program, in a well done manner imo, but the output is messed up. Me and my teacher both must be missing the problem, as we have tried several things to no avail. I know its gotta be something lame, the output is commented at the end of the program, its not commented but should be pretty easy to follow.
/*
the two smiley's are Deposit and Display.
*/
Code:/* Steven Billington Febuary 13, 2002 BankAccountCS2.cpp */ #include "stdafx.h" #include <iostream> #include <iomanip> using namespace std; class BankAccount { public: void get_initial(); void get_type(); void get_amount(); void Deposit(); void Withdrawl(); void Display(); private: double initial, amount, final; char type; }; int main(int argc, char* argv[]) { BankAccount Object; Object.get_initial(); Object.get_type(); Object.get_amount(); Object.Display(); return 0; } void BankAccount::get_initial() { cout << "Enter your previous balance: "; cin >> initial; } void BankAccount::get_type() { cout << "Withdrawl (W) or Deposit (D): "; cin >> type; type = toupper(type); switch (type) { case 'W': Withdrawl(); break; case 'D': Deposit(); break; default: cout << "Invalid selection\n"; } } void BankAccount::Withdrawl() { if (amount > initial) { cout << "Withdrawl is larger than funds, transaction aborted.\n"; } else { final = initial - amount; } } void BankAccount::Deposit() { final = initial + amount; } void BankAccount::get_amount() { cout << "How much would you like too " << type << "?: "; cin >> amount; } void BankAccount::Display() { cout << setiosflags(ios::fixed | ios::showpoint | ios::right) << setprecision(2); cout << "Starting Balance: " << initial << endl; cout << "Transaction Type: " << type << endl; cout << "Transaction Amount: " << amount << endl; cout << "New Balance: " << final << endl; } /* Output is the same no matter the input! Enter your previous balance: 20.00 Withdrawl (W) or Deposit (D): D How much would you like too D?: 14.00 Starting Balance: 20.00 Transaction Type: D Transaction Amount: 14.00 New Balance: -92559631349317831000000000000000000000000000000000000000000000.00 Press any key to continue */