Link to home
Create AccountLog in
Avatar of stallion5000
stallion5000

asked on

my array, that is tied to a class, is now filled with numbers, how do I total up whats in the array thats tied to a class?

class header

#include<iostream>
#include<string>

using namespace std;

#ifndef TRANSACTION
#define TRANSACTION

class transaction
{
private:
      string transactionType;
      string transactionAmountd, transactionAmountw;

public:

      void settransactionType(string type);
      string gettransactionType();

      void settransactionAmountd(string amount);
      string gettransactionAmountd();

      void settransactionAmountw(string amount);
      string gettransactionAmountw();
};
#endif


methods
#include "transaction.h"

void transaction::settransactionType(string type)
{
      transactionType = type;
}

string transaction::gettransactionType()
{
      return transactionType;
}

void transaction::settransactionAmountd(string amount)
{
      transactionAmountd = amount;
}

string transaction::gettransactionAmountd()
{
      return transactionAmountd;
}


void transaction::settransactionAmountw(string amount)
{
      transactionAmountw = amount;
}

string transaction::gettransactionAmountw()
{
      return transactionAmountw;
}


the functions, where my problem is.
void entertransactions(transaction transaction[],int const &items )
{      
      string stuff;
      
      char con = 'y';
      
      
      
      

      while((con !='n')&&(con !='N'))
      {
            for (int index = 0; index <=items; ++index)
            {
                  cout << "Enter Transaction Type, ex. Enter D for Deposit or W for Withdrawals";
                  getline(cin,stuff);
                  transaction[index].settransactionType(stuff);

                  if (transaction[index].gettransactionType() == "D" ||  transaction[index].gettransactionType() ==  "d")


                  {
                        cout << "Enter deposit amount";
                        getline(cin,stuff);
                        transaction[index].settransactionAmountd(stuff);

                  }
                  else
                  {
                        if (transaction[index].gettransactionType() == "W" ||  transaction[index].gettransactionType() ==  "w")
                        {
                              cout << "Enter withdrawal amount";
                        getline(cin,stuff);
                        transaction[index].settransactionAmountw(stuff);
                        }
                        else
                        {
                              cout << "Error, Please Enter a D for Deposit or W for Withdrawals";
                              
                        }}
                  index++;}
      

                  cout << "Enter Y to enter another transaction or No to go back to menue";
                  cin >> con;}
}


void displayAcount(transaction, items)                             (ok so I filled my array in the above part,
                                                                                        now I need to total it up what I put in here  transaction[index].settransactionAmountd(stuff);)
{
      string stuff;
      double totalD = 0;
      double totalW = 0;

for(int i=0; i==items; totalD += ????? maybe something like this     transaction[index].settransactionAmountd( );
      



      




ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer