Sol
Sol

Reputation: 265

How do you add doubles in a function with c++?

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;

Upvotes: 1

Views: 1832

Answers (1)

Ed Heal
Ed Heal

Reputation: 60017

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;
}

Upvotes: 4

Related Questions