Beginner C/C++

Moderators: None (Apply to moderate this forum)
Number of threads: 5430
Number of posts: 16951

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
about function Posted by trebla2352 on 3 Dec 2008 at 6:11 AM
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 _________ _________ _________ _________

You will see an incomplete funtion definition at the end of the program.. can you give some suggestions about this given problem

#include<iostream>
using std:: cout;
using std:: cin;
using std:: endl;

#include<iomanip>
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;}
}
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++}


Report
Re: about function Posted by Lundin on 3 Dec 2008 at 8:10 AM
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:

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



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.