OK, I'm new to C++. Brand new. I'm trying to teach myself. I have the
Fundamentals of C++: Understanding Programming and Problem Solving by Kenneth A. Lambert and Douglas W. Nance (copyright 1998) textbook. I'm using the Borland C++ Builder 5. I've copied a program straight from the book, character for character, and I've even copied and pasted a few C++ code snippets from this site. The problem I've had is that the commandprompt window, after running the program, closes immediately, thus I cannot see the results of the computations. The program from the book is a simple "checkbook balancing" program.
CODE
//Program file: chbook.cpp
//This program updates a checkbook
#include <iostream.h>
#include <iomanip.h>
int main ()
{
double starting_balance, ending_balance, trans_amount;
char trans_type;
//module for getting the data
cout << "Enter the starting balance and press <Enter>: ";
cin >> starting_balance;
cout << "Enter the transaction type (D) deposit or (W) withdrawl ";
cout << "and press <Enter>: ";
cin >> trans_type;
cout << "Enter the transaction amount and press <Enter>: ";
cin >> trans_amount;
//module for performing computations
if(trans_type == 'D')
ending_balance = starting_balance + trans_amount;
else
ending_balance = starting_balance - trans_amount;
//module for displaying results
cout << setiosflags (ios::fixed | ios::showpoint | ios:: right)
<< setprecision(2);
cout << endl;
cout << "Starting balance $" << setw(8)
<< starting_balance << endl;
cout << "Transaction $" << setw(8)
<< trans_amount << setw(2) << trans_type << endl;
cout << setw(30) << "-------" << endl;
cout << "Ending balance $" << setw(8)
<< ending_balance << endl;
return 0;
}
Is anything wrong with this code? Is there something I'm missing? Is there a different way to run these programs?
Moose