// Gregory Wong,6910, Project 3, Math374, 01, Spring 2011
#include <iostream>
#include <string>
#include "account.h"
#include "CheckAccount.h"
#include "SavingAccount.h"
usingnamespace std;
int main()
{
Check Check(1000.0);
Saving Saving(2000.0);
double credit=0.0;
double debit=0.0;
double interest = 0.1;
double cost = 2.0;
std::string command;
std::string secCommand;
std::cout<<"which account would you like to access?"<<"\n";
std::cout<<"Checkings"<<"\n";
std::cout<<"Savings"<<"\n";
getline (cin,command);
if (command != " ")// checkings if command is blank or containing a string
{
switch (command[0])
{
case'C'://if C is the first letter of the string then enter checkings
case'c':
while(secCommand !="Exit"||"exit") // while secCommand is not equal to exit loop
{
std::cout<<"Enter command as shown:"<<endl;
std::cout<<"Deposit"<<endl;
std::cout<<"Withdraw\t(There will be a fee deducted from your balance)"<<endl;
std::cout<<"Show Balance"<<endl;
std::cout<<"Exit"<<endl;
getline (cin,secCommand);
switch (secCommand[0])// switch statement to select correct command
{
case'D':// if d is the first letter of the string then deposit
case'd':
std::cout<<"Enter amount that you will like to deposit:"<<endl;
std::cin>>credit;
Check.creditBalance(credit);
Check.print();
std::cout<<"\n";
break;
case'W':// if w is the first letter of the string then withdraw
case'w':
std::cout<<"Enter amount that you will like to withdraw:"<<endl;
std::cin>>debit;
Check.setfee(cost);
Check.debitBalance(debit);
Check.print();
std::cout<<"\n";
break;
case'S':// if s is the first letter of the string then show balance
case's':
Check.print();
std::cout<<"\n";
break;
default:
secCommand = "Exit";
break;
}
}
break;
case'S'://if S is the first letter of the string then enter savings
case's':
while(secCommand!="Exit"||"exit")
{
std::cout<<"Enter command as shown:"<<endl;
std::cout<<"Deposit"<<endl;
std::cout<<"Withdraw"<<endl;
std::cout<<"Calculate Interest"<<endl;
std::cout<<"Show Balance"<<endl;
std::cout<<"Exit"<<endl;
getline (cin,secCommand);
if(secCommand!=" ")
{
switch (secCommand[0])
{
case'D':
case'd':
std::cout<<"Enter amount that you will like to deposit:"<<endl;
std::cin>>credit;
Saving.creditBalance(credit);
Saving.print();
std::cout<<"\n";
break;
case'W':
case'w':
std::cout<<"Enter amount that you will like to withdraw:"<<endl;
std::cin>>debit;
Saving.debitBalance(debit);
Saving.print();
std::cout<<"\n";
break;
case'C':
case'c':
std::cout<<"Your Balance including interest:"<<endl;
Saving.modifyInterestRate(interest);
Saving.calculateInterest();
Saving.print();
std::cout<<"\n";
break;
case'S':
case's':
Saving.print();
std::cout<<"\n";
break;
default:
secCommand = "Exit";
break;
}
}
else
secCommand ="Exit";
}
break;
}
}
else
{
return main();
}
system("pause");
return 0;
}
i keep getting a error after runtime, right after i enter an amount to deposit/withdraw the error interrupts the runtime.
if there is any other errors please dont hesitate to mention it.
also how would i use a vector of account pointers to savings and checkings? (i do have savings and checkings class in seperate headers (entire program is 3 headers and 4 cpps) ) i want to implement polymorphism
We'd need to see the code for the "Check" class. When you IDE gives you this error, there is probably the option to debug the code and go to where the error is occurring. That would be helpful too. Also, this shouldn't compile since you have, on line 13/14, variables with the same name as a class.
If you want polymorphism, make the vector and vector of pointers to the base class type.