• 0

[C++] Whats wrong with this code?


Question

I've never written a class before and have been following as many examples as I can, but something is wrong. Anything obvious im missing? THanks in advance!

class Account
{
public:
	void  SetBalance(float balance);
	float Deposit(float d);
	float Withdrawal(float w);
	float GetBalance();

private:
	float balance;

};

#include "Account.h"
#include<iostream>

void Account::SetBalance(float balance)
{
	balance = bal;
}

float Account::Deposit(float d)
{
	float d;
	balance = d + balance;
	return bal;
}

float Account::WithDrawal(float w)
{
	float w; 
	if (w <= balance)
	balance = balance - w;
	return 1;

	else 
	return 0;
}

float Accoutn::GetBalance()
{
	return balance;

};

Edited by gameguy
Link to comment
Share on other sites

9 answers to this question

Recommended Posts

  • 0

So if i wanted to test the class,

#include "Account.h"

#include<iostream>

int main()

{

using namespace std;

Account b;

b.SetBalance(float bal)

return 0;

}

would that work to send a value in?

Link to comment
Share on other sites

  • 0

well... it should work but there is no way to tell you what the balance is.... mkaing like a PrintBalance method so you can return the balance.... also u dont do

b.SetBalance(float bal)

more like:

float newBal = 100.99;
b.SetBalance(newBal);

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.