-2

The question was to create a class named ACCOUNTS with a read function to accept the sales and purchases and then to create a friend function to print total tax to pay. I have tried doing this, but I keep getting the error that the funtion read and tottax have too few arguments. What can I correct?

#include<stdio.h>
    #include<iostream>
    using namespace std;
    class ACCOUNTS
    {   
        public:
        ACCOUNTS(){sales=0,purchase=0;}
        private:
            int sales,purchase;


        friend void tottax(ACCOUNTS &sfo);
        friend void read(ACCOUNTS &sfo);
    };
        void read(ACCOUNTS &sfo)
        {
            cout<<"Enter saleamt : \n";
            cin>>sfo.sales;
            cout<<"Enter purchaseamt : \n";
            cin>>sfo.purchase;
        }
        void tottax(ACCOUNTS &sfo)
        {
            int tax=(sfo.sales-sfo.purchase)*(4/100);
            cout<<"\nTax : "<<tax;
        }
        int main()
        {
            read();
            tottax();
            return 0;
        }

1 Answers1

1

void tottax(ACCOUNTS &sfo) says; hey, I am a function which does not return a single bit (void as return type), but I need an object of type ACCOUNTS to be called. So you either give me one, or I am not gonna execute.

In your main you are calling tottax in the following way: tottax() which translates to: Dear compiler could you please call the function tottax, the one which does not take any parameter? The compiler look at you r source code and try to find something like: void totax(){...} which clearly does not exists cause the only version of tottax you wrote takes one and only one parameter.

So again, the problem is that, tottax wants one and only one parameter. That is why the compiler is complaining.

Plus think about it a bit more: tottax computes something that is related to an ACCOUNTS. If you don't provide one, what is it gonna compute?

The same holds for the function read.

Davide Spataro
  • 7,319
  • 1
  • 24
  • 36