Answer to Question #268748 in C++ for Marie

Question #268748

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!


1
Expert's answer
2021-11-19T17:13:17-0500


#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS