0

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 by Nick Evan: Fixed formatting

2
Contributors
10
Replies
12
Views
6 Years
Discussion Span
Last Post by Tamlyn
Featured Replies
  • You failed to include <iostream> and <string> and the [icode]using std::cin;[/icode], [icode]using std:cout;[/icode] and [icode]using std::string;[/icode] statements. Read More

  • 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??? Read More

  • 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. Read More

  • 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. [icode] updateDifference(cashPrice, creditPrice, totalOfDifferences); cout << " prices is now R " << totalOfDifferences << endl; [/icode] Read More

1

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

Edited by Ancient Dragon: n/a

0

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

0

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

1

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???

0

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

1

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 by Ancient Dragon: n/a

0

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;

1

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

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

Oh you mean like this. thanks :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.