Error: Too many arguements to function

So What I am trying to do is to make a list with choices and have you enter an amount and "purchase" them, then giving you change or saying it is lower than cost. My problem is that it keeps saying within the switch statement "[Error] too many arguments to function 'int sellItem()' " when I have tried to compile and run it, I have tried different things but I am stumped on what to do. (this is homework btw, so I am hoping if I could get an explanation as to why the code is wrong or won't work that would help or a link would do too.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <iomanip>
using namespace std;

class itemDispenser //class to define the item chosen

{
private:

    int itemsInStock;
	
    double itemCost;

public:

    itemDispenser(int setStock, double setCost); //object has stock and cost variables

    int getStock();
    double getCost();
    void dispense(); //dispenses item and reduces stock
    

};

int main()
{
	itemDispenser candy(2, 2.00);
	itemDispenser chips(2, 2.00);
	itemDispenser gum(2, 2.00);
	itemDispenser cookies(2, 2.00);

	int choice;
	int selectionScreen();
	int sellItem();
 	
	cin >> choice;

do
	{
		selectionScreen();
   		cin >> choice;
   		switch (choice)
   		{
       		case 1: sellItem(candy); break;
        	case 2: sellItem(chips); break;
        	case 3: sellItem(gum); break;
       		case 4: sellItem(cookies); break;
       		case 5: break;
       		default: cout << "Try Again" << endl; break;
      	}	

	}while(choice!=5);
}

void sellItem(itemDispenser& selection) //takes money and dispenses item
{
	double payment;
	double difference;

	if (selection.getStock() > 0) //if there are still items in stock
	{
		cout << "Pay $" << fixed << setprecision(2) << selection.getCost() << " for item." << endl;
		cin >> payment;
	}
}
Last edited on
 
double sellItem(); //this has no arguments  


unless you have the function declared elsewhere sellItem has no arguments and doesn't currently do anything....
Topic archived. No new replies allowed.