Hey guys
Here's my code that is giving me a compiler error ?
Why is my darling computer complaining so horribly about what I always do with cin and cout which is give them their respective accessories >> and << ?

Here's the code for the main function:

int main()
{

    string description;
    int shelfStay;
    float wholesalePrice, cashPrice, creditPrice, totalOfDifferences;
// initialise total
   totalOfDifferences = 0;



    inputAndValidate(description, shelfStay, wholesalePrice);
    determinePrices(shelfStay,wholesalePrice, cashPrice, creditPrice);
    updateDifference(cashPrice, creditPrice, totalOfDifferences);
    cout.setf(ios::fixed);
    cout.precision(2);
    cout << description << " is expected to stay on the shelf for " << shelfStay << " days and has a wholesale price"
         << endl << " of "
        << "R" << wholesalePrice << endl;

        cout << " The cash price for " << description << " is R" << wholesalePrice << endl;

        cout << "The total of the difference between the cash and credit" << endl;
        [COLOR="red"]cout << " prices is now R " << updateDifference(cashPrice, creditPrice, totalOfDifferences)  << endl;[/COLOR]

        return 0;


        system("pause");
        return 0;
}

This is the negativity it gives me:

 no match for 'operator<<' in 'std::operator<< [with _Traits = std::char_traits<char>](((std::basic_ostream<char, std::char_traits<char> >&)(&std::cout)), ((const char*)" prices is now R ")) << updateDifference(cashPrice, creditPrice, ((float&)(&totalOfDifferences)))' 

I'm using devc++ and I've changed my compiler settings and changed my make to: g++ but that didn't work. My make is now mingw32-make.

Hope you guys can help ;)

Edited 3 Years Ago by Nick Evan: Fixed formatting

You failed to include <iostream> and <string> and the using std::cin; , using std:cout; and using std::string; statements.

Edited 5 Years Ago by Ancient Dragon: n/a

OH sorry I forgot to put that at the top: Wouldn't "#include <iostream>
using namespace std"; be alright ? That's what I've currently got but I've now just included <string> as a header file and it still give's me the same complaint

void updateDifference(float cashPriceP, float creditPriceP, float & totalOfDifferencesP)
{
float difference;
difference = cashPriceP - creditPriceP;
totalOfDifferencesP += difference;
}

That's what I thought. Its a void function. How do you expect cout to print the return value of a function that doesn't return anything???

Oh thanks:) But I have no idea how to solve this. I'm still very new to the whole function section of c++.

The way to solve it is not to put that function call on the same line as the cout statement. Put that function call statement on its own line before that cout line so that the cout and display the new values of those variables.

Edited 5 Years Ago by Ancient Dragon: n/a

This is what I originally tried. I don't understand why it doesn't work.

[in main]
totalOfDifferences = updateDifference(cashPrice, creditPrice, totalOfDifferences)

[and at the end]
cout << " prices is now R " << totalOfDifferences << endl;

Since updateDifference() is a void function you can't set a variable = to it. The function is going to change the value of totalOfDifferences because it's passes by reference. Example below.

updateDifference(cashPrice, creditPrice, totalOfDifferences);
cout << " prices is now R " << totalOfDifferences << endl;

cout << " prices is now R " << updateDifference << endl;

Oh you mean like this. thanks :)

This question has already been answered. Start a new discussion instead.