Testing Environment: MS Visual 2010 Ultimate.
I have two functions that need to pass from one to the other.
function 1:
//Record which account was chosen
string Account::getAccountType()
{
if (accountType == 1)
{
return "Account Type: Chequing";
}
else
{
return "Account Type: Savings";
}
};
This function will take the user's input and identify whether Chequing was selected or Savings.
Function 2:
//Print the Account Statement
void Account::PrintStatement()
{
cout << "First Name: " << firstName << endl;
cout << "Last Name: " << lastName << endl;
cout << "SIN Number: " << sinNumber << endl;
cout << "Account Type: " << accountType << endl;
cout << "Transactions: " << transactions << endl;
cout << "Final Balance: " << balance << endl;
};
This function gets all the global variables that had their values returned, or inputs saved, and prints all the inputs and calculations made.
main.cpp:
//Retrieve client information
cout << "Please fill out the information below for registration:" << endl;
cout << "Enter first name: ";
cin.getline(firstName, 255);
cout << "Enter last name: ";
cin.getline(lastName, 255);
cout << "Enter SIN number: ";
cin.getline(sinNumber, 255);
cout << "Enter initial balance: ";
cin >> balance;
cout << "Enter account type:\n Chequing - 1\n Savings - 2 (Or any number)\n Choice: ";
cin >> accountType;
cout << "\nPlease wait..." << endl;
My problem:
When accountType
is printed (via PrintStatement()
), it shows the integer value that the user inputted. I understand why it does that. I just don't know how to change it so that when either 1 or a different number was used, the PrintStatement()
function would display the appropriate account (Chequing or Savings).
What I tried: I tried changing function 1 into an integer based function and have accountType equal the option of Chequing or Savings, but integers cannot store a string value. I tried using char instead but I get the const char error.
What I'd like to do:
I want to be able to take the user's input of any number, and pass it to the PrintStatement()
(via another function) so it can display the appropriate account.
EDIT (adding additional code for clarity)
account.cpp
//Initializing account entities
Account::Account(char fn[], char ln[], char sin[], double bal, int actype, int trans)
{
strcpy(firstName, fn);
strcpy(lastName, ln);
strcpy(sinNumber, sin);
balance = bal;
accountType = actype;
transactions = 0;
};
account.h
#define ACCOUNT_H
#include <iostream>
#include <cstring>
using namespace std;
class Account {
public:
//Object constructor
Account(char firstName[], char lastName[], char sinNumber[], double balance, int accountType, int transactions);
//Object operations
double DepositAmt(double amount);
double WithdrawAmt(double amount);
void PrintStatement();
double getFinalBalance(double fbal);
string getAccountType();
double getTransactions (double cDeposit, double cWithdraw);
private:
//Object properties
char firstName[255];
char lastName[255];
char sinNumber[255];
double balance;
int accountType;
int transactions;
};