1
votes

Basically I have my doubles set in c++ and for some reason it gives me this error

"..\project2_name.cpp:56:9: error: assignment of function 'double total(double, double, double)'".

double appleprice=0;
double pearprice=0;
double tomatoprice=0;
double completetotal=0;


double total(double appleprice, double pearprice, double tomatoprice)
{
    total = appleprice + pearprice + tomatoprice;
        return total;
}

I have a switch case that calls this from a menu that works except the total: case '3': cout<< "You added a tomato" << endl; tomato = productsadd(tomato); price = 3.02; tomatoprice = addprice(price); cout << "You have on order " << tomato << " tomatos." << endl; break;

    case '4':
        cout<< "Your Full order" << endl;
        completetotal = total(appleprice, pearprice, tomatoprice);
        cout << "You have on order " << apple << " apples. " << appleprice << " price."<< endl;
        cout << "You have on order " << pear << " pears. " << pearprice << " price."<< endl;
        cout << "You have on order " << tomato << " tomatos. " << tomatoprice << " price."<< endl;
        cout << "You have a total of " << completetotal << endl;
        break;
1
total is the name of the function. You cannot assign to the function. Make a temporary variable instead.krzaq
I see... duh. (smacks my head)Sol
Some languages, like Pascal, allow return values to be assigned to the function's name without declaring a variable for it. C/C++ don't work that way.Remy Lebeau

1 Answers

4
votes

As total is the name of the function - you cannot use this. Use a temporary variable or perhaps change the code to

double total(double appleprice, double pearprice, double tomatoprice)
{
    return appleprice + pearprice + tomatoprice;
}