Create a C program that would make a simple checkbook balancer that would input a sequence of deposits (positive floating-point values) and issuances (negative floating-point values) terminated by a 0. It would output the transaction type, the amount and the running balance for each entry. Assume the initial balance of 0. Ensure that the issued check won’t bounce!
#include <iostream>
using namespace std;
int main()
{
float deposits[100];
float issuances[100];
float total[100];
cout<<"\nEnter values:\n";
int countPos=0;
int countNeg=0;
while(true){
int val;
cin>> val;
if (val==0){
break;
}
else{
if (val>0){
deposits[countPos]=val;
countPos++;
}
else if(val<0){
issuances[countNeg]=val;
countNeg++;
}
}
}
cout<<"\nType\tAmount\tBalance";
for(int i=0;i<countPos;i++){
float balance=0;
cout<<"\nDeposit\t"<<deposits[i]<<"\t"<<(balance+deposits[i]);
}
for(int i=0;i<countNeg;i++){
float balance=0;
cout<<"\nIssuance\t"<<issuances[i]<<"\t"<<(balance-issuances[i]);
}
return 0;
}
Comments
Leave a comment