天之道

享受编程的乐趣。
posts - 118, comments - 7, trackbacks - 0, articles - 0
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

The credit card codes

Posted on 2011-09-23 01:13 hoshelly 阅读(266) 评论(0)  编辑 收藏 引用 所属分类: C++


Tonight I was studying the credit card codes, all of these was copied from my book,"C++ ——how to program".

This are the program demand:
1)Account number(an integer);
2)Balance at the begining of the month;
3)Total all items charged by this customer this month;
4)Total of all items applied to this customer's account this month;
5)Allowed credit limit.


The program should input each of these facts, calculate the new balance(=begining balance+charges-credits) and determine if the new balance exceeds the customer credit limit.
For those customers whose credit limit is exceeded, the program should display the customer's account number,credit limit,new balance and the message "Credit limit exceeded".

#include<iostream>
#include
<iomanip>// formatting integers and the precision of floating point values
using namespace std;

int main()
{
    
int accountNumber;
    
double balance,charges,credits,limit;

    cout
<<"Enter account number(-1 to end):"
        
<<setiosflags(ios::fixed|ios::showpoint);// to convert data from fixed point number representation to floating point representation
    cin>>accountNumber;
    
while(accountNumber!=-1)
    
{
        cout
<<"Enter beginning balance:";
        cin
>>balance;
        cout
<<"Enter total charges: ";
        cin
>>charges;
        cout
<<"Enter total credits:";
        cin
>>credits;
        cout
<<"Enter credit limit:";
        cin
>>limit;
        balance
+=charges-credits;

        
if(balance>limit)
            cout
<<"Account:  "<<accountNumber
                
<<"\nCredit limit: "<<setprecision(2)<<limit //accurate to two decimal point
                
<<"\nBalance:    "<<setprecision(2)<<balance
                
<<"\nCredit Limit Exceeded.\n";
        cout
<<"\nEnter account number(-1 to end): ";
        cin
>>accountNumber;
    }


    cout
<<endl;
    
return 0;
}


 

input -1 and the program will be ended.


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理