My code compiles fine but how do I ADD these 3 things to my code before it says credit limit exceeded.... Can someone show me...
Account: 100
Credit Limit: 5500.00
Balance: 5894.78
Then which is already in my code Credit limit exceeded....
Here is my code:
#include %26lt;iostream%26gt;
#include %26lt;iomanip%26gt;
using std::cout;
using std::cin;
using std::endl;
using std::fixed;
# include %26lt;iomanip%26gt;
using std::setprecision;
int main()
{
int accountNumber; // Customers account number
double balance; // Customers balance
double charges; // Charges on the account
double credits; // Credits to the account
double limit; // Credit limit on the account
cout %26lt;%26lt; "Enter account number (-1 to end): " %26lt;%26lt; fixed;
cin %26gt;%26gt; accountNumber; // Code to read customer's account number
while (accountNumber != -1) // begin loop
{
cout %26lt;%26lt; "Enter beginning balance: " %26lt;%26lt; endl; // prompt and read the customers balance
cin %26gt;%26gt; balance;
cout %26lt;%26lt; "Enter total charges: " %26lt;%26lt; endl; // prompt and read the customers charges
cin %26gt;%26gt; charges;
cout %26lt;%26lt; "Enter total credits: " %26lt;%26lt; endl; // prompt and read the customers credit
cin %26gt;%26gt; credits;
cout %26lt;%26lt; "Enter credit limit: " %26lt;%26lt; endl; // prompt and read the customers credit history
cin %26gt;%26gt; limit;
balance = balance + charges - credits; // calculate the new customers balance
if (balance + charges - credits %26gt; limit) // determine if customers credit limit is exceeded
cout %26lt;%26lt; "Credit Limit Exceeded." %26lt;%26lt; endl; // if customers limit is exceeded print message
cout %26lt;%26lt; "\nEnter account number (-1 to end): ";
cin %26gt;%26gt; accountNumber; // reading customers account number
} // End while loop....
cout %26lt;%26lt; endl; // ensure all output is displayed
return 0;
} // end main
Using C++ .....?
You already reassigned balance to equal balance + charges - credits.... so you dont need to say it again in your if statement or else it will be off.
also shouldnt it be balance PLUS credits MINUS charges?
try:
if(balance %26gt; limit)
{
cout %26lt;%26lt; "Credit Limit Exceeded."
}
make sure you bracket because your cout statement is not on the same line as your if statement.
Good Luck
Hope it Helped
R
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment