0
votes

simple program tells u how much milk costs whatever i dont get why i get this error "no match for 'operator>>' in 'std::cin??" im a beginner at c++ but still what the hell.

also this error: "In function 'int main()':"

#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or      input loop */

const double CARTONLOAD = 3.78;
const double CARTONCOST = 3.78 * .38;
const double CARTONPROFIT = 0.27;

int main() 
{
    double totalmilk = 0;
    double milkcartonsneeded = 0;
    double milkcost = 0;

    cout << "Enter total amount of milk produced in the morning in Liters" << endl;
    cin >> totalmilk >> endl;
    milkcartonsneeded = totalmilk/CARTONLOAD;
    cout << " Number of milk cartons needed to hold milk: "  << milkcartonsneeded << endl;
    milkcost = milkcartonsneeded * CARTONCOST;
    cout << " The cost of producing milk is: " << milkcost << endl;
    cout << " The profit for producing milk is: " << milkcartonsneeded * CARTONPROFIT - milkcost << endl;

    return 0;
}
3

3 Answers

7
votes

endl is an output stream manipulator. cin is an input stream. I'm not sure what you expect endl to do here:

cin >> totalmilk >> endl;

But it's wrong.

4
votes

This is the problem

cin >> totalmilk >> endl;

It is giving error because of endl. Remove it.

1
votes

operator<< has an overload that takes a function pointer to a function that receives an std::basic_ostream. This allows you to use "stream manipulators", i.e. std::endl, in a operator<< chain. This allows you to do the following for example:

std::cout << "hey.";
std::endl(std::cout);
std::cout << "hello.";

Because std::endl is just a function that takes a std::basic_ostream. However, it also returns one by reference (similar to operator<<), meaning it can appear in a chain, i.e. std::cout << std::endl.

Since std::cin is a std::basic_istream, you have incompatible arguments.