help with calling a member function?

I'm supposed to write a cashier program using a class. However, I'm having some troubles. Earlier I was getting an error that there weren't enough arguments in m.subtract(); and I realize that's true but I have no idea what to put in the parentheses. I tried m.subtract(owed, paid); but it didn't work. (I wanted owed and paid to be user entered) and I changed a few things around but that made it worse because now I'm getting an error that subtract(); is not a member function. Any help you could give me on this is greatly appreciated! Also I know that it's far from done but I'm stuck and could use some help getting past this error

header.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef header_H
#define header_H

class Change {
	float owed;
	float paid;
public:
	Change() {
		owed = 0;
		paid = 0;
	}

	void input() {
		cout << “Input the amount owed”;
		cin >> owed;
		cout << “Input the amount paid”;
		cin >> paid;

	float subtract(float owed, float paid) {
			return owed - paid;
		}
};
#endif header_H 


source.cpp
1
2
3
4
5
6
7
8
9
10
11
#include "change.h"
#include <iostream>
using namespace std;

int main() {

	Change m;
	m.input();
	m.subtract();

	}
Last edited on
Line 19: Get rid of the arguments. You want to use the member variables, not the arguments.

1
2
3
float subtract () 
{  return owed - paid;
}


Line 18: You're missing a }

source.cpp line 9: You don't do anything with the returned value.

Line 10: main should have a return 0;

Last edited on
Topic archived. No new replies allowed.