Re: [Dev-C++] while termination problems
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Reid T. <rei...@at...> - 2004-10-06 03:00:04
|
as a note, you should avoid using C and C++ headers in the same program,
use cin.get rather than system("PAUSE") to keep your window around. You
should also initialize your variables before using them.
not sure if this is what you mean,,,... but....
#include <iostream>
#include <iomanip>
using namespace std;
int
main(int argc, char *argv[])
{
/* arbitrarily initializing all of these to 0 */
double acctnum = 0;
double bBal = 0;
double nBal = 0;
double charges = 0;
double limit = 0;
double credits = 0;
while (acctnum != -1)
{
cout << "Enter account number (enter -1 to end): ";
cin >> acctnum;
if (acctnum == -1)
{
break; /* break the while loop */
}
cout << "Enter beginning balance: ";
cin >> bBal;
cout << "Enter total charges: ";
cin >> charges;
cout << "Enter total credits: ";
cin >> credits;
cout << "Enter credit limit: ";
cin >> limit;
nBal = bBal + charges - credits;
cout << "Account:" << setw(13) << acctnum << "\n";
cout << "Credit Limit:" << setw(9) << limit << "\n";
cout << "Balance:" << setw(14) << nBal << "\n";
if (nBal > limit)
cout << "Credit Limit Exceeded.\n";
}
cin.ignore();
cin.get();
return 0;
}
|