I am trying to make an ATM machine, while trying to teach myself how classes interact with each other. I feel as though the main idea of the program is correct, but as you can see, I am having a lot of syntax errors.
If you guys see something that I am doing wrong (evidently there are several), can you please point them out. Thanks ahead of time guys :).
Here are my errors:
source1.cpp(28) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
source1.cpp(39) : warning C4183: 'Credit': missing return type; assumed to be a member function returning 'int'
source1.cpp(41) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
source1.cpp(52) : warning C4183: 'Debit': missing return type; assumed to be a member function returning 'int'
source1.cpp(59) : error C2236: unexpected 'class' 'SavingsAccount'. Did you forget a ';'?
source1.cpp(59) : error C2143: syntax error : missing ';' before ':'
source1.cpp(13) : error C2059: syntax error : ':'
source1.cpp(59) : error C2059: syntax error : 'public'
source1.cpp(60) : error C2143: syntax error : missing ';' before '{'
source1.cpp(60) : error C2447: '{' : missing function header (old-style formal list?)
source1.cpp(100) : error C2628: 'CheckingAccount' followed by 'int' is illegal (did you forget a ';'?)
source1.cpp(101) : error C3874: return type of 'main' should be 'int' instead of 'CheckingAccount'
source1.cpp(103) : error C2065: 'SavingsAccount' : undeclared identifier
source1.cpp(103) : error C2146: syntax error : missing ';' before identifier 'S1'
source1.cpp(103) : error C3861: 'S1': identifier not found
source1.cpp(117) : error C2228: left of '.Newbalance' must have class/struct/union
1> type is ''unknown-type''
source1.cpp(82) : error C2512: 'Account' : no appropriate default constructor available
#include <iostream>
using namespace std;
class Account
{
private:
protected:
double balance;
double n;
double s;
public:
Account(double balance)
{
cout << "Please enter your starting balance" << endl;
cin >> balance;
if (balance<0.00)
{
cout << "Insufficient funds.... you have $0.00" << endl;
balance = 0.00;
}
else
{
cout << "Your account has been created" << endl;
}
}
Credit(double n)
{
cout << "How much money would you like to add?" << endl;
cin >> n;
if (n>0.00)
{
balance = n + balance;
}
else
{
cout << "That is not a correct amount to add" << endl;
}
}
Debit(double s)
{
cout << "How much would you like to remove?" << endl;
cin >> s;
if(s>balance)
{
cout << "You are attempting to overdraw" << endl;
}
else
{
balance = balance - s;
}
}
void DisplayAccount()
{
cout<< "Your current balance is" << balance << endl;
}
}
class SavingsAccount : public Account
{
protected:
double interest;
public:
SavingsAccount(double interest)
{
cout<<"Please enter the interest rate" << endl;
cin >> interest;
}
void Newbalance()
{
balance = interest * balance;
}
}
class CheckingAccount : public Account
{
protected:
double m;
double n;
public:
CheckingAccount(double m)
{
cout << "How much would you like to remove?" << endl;
cin >> m;
if(m>balance)
{
cout << "You are attempting to overdraw" << endl;
}
else
{
n= 2.25;
m= m*n;
balance = balance - m;
}
}
}
int main()
{
CheckingAccount C1(100.0);
SavingsAccount S1(300.0);
Account * ac;
ac = &C1;
ac->Credit(50.0);
ac->Debit(10.0);
ac->DisplayAccount();
ac->Debit(200.00);
ac->DisplayAccount();
ac = &S1;
ac->Credit(150.10);
ac->Debit(20.0);
ac->DisplayAccount();
S1.Newbalance();
ac->DisplayAccount();
return 0;
}