Function call - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Function call

Write a program that determines the ending balance given the starting balance, a transaction amount and the transaction type.

[code]
#include
using std:: cout;
using std:: cin;
using std:: endl;

#include
using std:: setprecision;
using std:: setiosflags;
using std:: setw;

double PerformCompute( double Sbal, char transType, double TAmt);

int main()
{ double startingBalance, endingBalance, transAmount;
char tran;

cout<<"Enter the starting balance and press <Enter>:";
cin>>startingBalance;

cout<<"Enter transaction type (D) deposit or (W) withdrawal"<<endl<<endl<< and press <Enter>";
cin>>transAmount;

endingBalance=PerformCompute(startingBalance, tran, transAmount);

cout<<setiosflags(ios::fixed|ios::showpoint|ios::right);
cout<<setprecision(2)<<endl;
cout<<"Starting Balance "<<startingBalance<<endl<<"Transaction ""<<transAmount<< " "<<tran <<endl;
cout<<"Ending Balance "<<endingBalance<<endl;
return 0;
}

double PerformCompute(double Sbal, char transType, double TAmt)
{

WHAT WILL BE TYPED HERE??!!

}
[/code]


Actually, Im still figuring out what will be the missing arguments in the function definition.. I did not fully understand the problem.. there is something to withdraw and deposit..

can you give suggestions, specifically, those who have understanding in accounting problems..<<<Thanks>>

Comments

  • phillcahillphillcahill Posts: 18Member
    This answers the question.

    Most of the code i used is yours but changed a few bits. The W or D Needs validation to imrove quality and gain you marks but you can do that your self. Don't forget to comment your code.

    double PerformCompute( double Sbal, char transType, double TAmt);

    int main()
    {
    double startingBalance, endingBalance, transAmount;
    char tran;

    cout<<"Enter the starting balance and press <Enter>:";
    cin>>startingBalance;

    cout<<"Enter transaction type (D) deposit or (W) withdrawal and press <Enter>";
    cin>>tran;

    cout<<"Enter transaction amount <Enter>:";
    cin>>transAmount;

    endingBalance=PerformCompute(startingBalance, tran, transAmount);

    cout<<"Starting Balance "<<startingBalance<<endl<<"Transaction "<<transAmount<< " "<<tran <<endl;
    cout<<"Ending Balance "<<endingBalance<<endl;

    getch();
    return 0;
    }

    double PerformCompute(double Sbal, char transType, double TAmt)
    {
    if(transType=='D')
    {
    return Sbal += TAmt;
    }
    else
    {
    return Sbal -= TAmt;
    }
    }

Sign In or Register to comment.