about function - Programmers Heaven

Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

about function

Modify the given program so that if allows the user to repeat the process for several transactions using the while loop. The program should call function DispTrans that tabulates the transaction information as tabulated below. The program provides for a maximum of 20 transactions, but allows the user to enter the actual number of transactions.
Outputs Tabulation Format:
TransType Beg.Balance DepositAmt WithdrawAmt End.Balance
_________ _________ _________ _________ _________
_________ _________ _________ _________ _________
Totals _________ _________ _________ _________

[color=Green]You will see an incomplete funtion definition at the end of the program.. can you give some suggestions about this given problem[/color]

[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)
{double a,b;
if(transType=='D' || transType=='d')
{a=Sbal+TAmt;
return a;}
if (transType=='W' || transType=='w')
{b=Sbal -TAmt;
return b;}
}
[color=Blue]double DispTrans(
{int i=1,m;
while(i<=20)
{if(transType=='D' || transType=='d')
{cout<<"Enter the transaction: ";
cin>>m;}
if(transType=='W' || transType=='w')
{cout<<"Enter the transaction: ";
cin>>m;}
i++}[/color]

[/code]

Comments

  • LundinLundin Posts: 3,711Member
    I believe that your teacher want the while loop to be in main(). This means that transType must be passed to the function through a parameter.

    Also, the indention is horrible. You should make the program readable by doing something like this:

    [code]double DispTrans(char transType)
    {
    int m;

    if(transType=='D' || transType=='d')
    {
    cout<<"Enter the transaction: ";
    cin>>m;
    }

    if(transType=='W' || transType=='w')
    {
    cout<<"Enter the transaction: ";
    cin>>m;
    }
    }
    [/code]
Sign In or Register to comment.