Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
1>c:\users\public\documents\c++ data\saham\saham\saham.cpp(83): error C2186: '-' : illegal operand of type 'void'
this error is for bold lines
// saham.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<queue>
#include<iostream>
using namespace std;

int main()
{

  queue<int> boughtn ;
  queue<int> soldn ;
  queue<int> boughtp ;
  queue<int> soldp ;
  int boughtnum ;
  int boughtprice ;
  int soldnum ;
  int soldprice ;
  int benefit = 0 ;
  cout << "Please enter number of bought stocks (enter 0 to end):\n" << endl ;
 
  do
  {
    cin >> boughtnum ;
    boughtn.push (boughtnum);

  }
  while (boughtnum);

   cout << "Please enter price of bought stocks (enter 0 to end):\n" << endl ;
 
  do
  {
    cin >> boughtprice ;
    boughtp.push (boughtprice);
  }
  while (boughtprice);

  cout << "Please enter number of sold stocks (enter 0 to end):\n" << endl ;
 
  do
  {
    cin >> soldnum ;
    soldn.push (soldnum);
  }
  while (soldnum);

   cout << "Please enter price of sold stocks (enter 0 to end):\n" << endl ;
 
  do
  {
    cin >> soldprice ;
    soldp.push (soldprice);
  }
  while (soldprice);
  

  //while ( ( !boughtn.empty() ) & ( !soldn.empty() ) )
  //{
	
	  
	/*  boughtn.changedata( soldn.front() );
	  benefit += soldn.pop() * ( soldp.pop() - boughtp.front());
	  boughtnum = boughtnum - soldnum ; 
	 benefit = benefit + ( boughtprice - soldprice ) * soldnum ;*/

	   while ( ( !boughtn.empty() ) & ( !soldn.empty() ) )

	{
		   boughtn.front();
	   boughtn.pop() ;
	   boughtp.front();
	   boughtp.pop() ;
	   soldp.front();
	   soldn.pop() ;
	   soldn.front();
	   soldp.pop() ;
		if ( boughtn.front() > soldn.front() )

		{
			//boughtn.changeData( soldn.front() );
			benefit += soldn.pop() * ( soldp.pop() - boughtp.front() ) ;
		}

		else

		{
		//	soldn.changeData( boughtn.front() );
			benefit += boughtn.pop() * ( soldp.pop() - boughtp.pop() ) ;
		}
   }
        cout << "The benefit is " << benefit << endl ;
   }
//}
Posted
Updated 29-Jun-11 22:04pm
v2

pop does not return a value, so I assume that is your problem ( despite you not telling us what line has the error ).
 
Share this answer
 
I am not sure about your problem but what you want is should be like the example below:

#include "stdafx.h"
#include<queue>
#include<iostream>
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
	queue<int> boughtn ;
  queue<int> soldn ;
  queue<int> boughtp ;
  queue<int> soldp ;
  int boughtnum ;
  int boughtprice ;
  int soldnum ;
  int soldprice ;
  int benefit = 0 ;
  cout << "Please enter number of bought stocks (enter 0 to end):\n" << endl ;
 
  do
  {
    cin >> boughtnum ;
    boughtn.push (boughtnum);
 
  }
  while (boughtnum);
 
   cout << "Please enter price of bought stocks (enter 0 to end):\n" << endl ;
 
  do
  {
    cin >> boughtprice ;
    boughtp.push (boughtprice);
  }
  while (boughtprice);
 
  cout << "Please enter number of sold stocks (enter 0 to end):\n" << endl ;
 
  do
  {
    cin >> soldnum ;
    soldn.push (soldnum);
  }
  while (soldnum);
 
   cout << "Please enter price of sold stocks (enter 0 to end):\n" << endl ;
 
  do
  {
    cin >> soldprice ;
    soldp.push (soldprice);
  }
  while (soldprice);  
	
 
	 while ( ( !boughtn.empty() ) & ( !soldn.empty() ) )
 
	{
		   int &iBoughtn = boughtn.front();
		   int &iSoldn = soldn.front();
		   int &iSoldp = soldp.front();
		   int &iBoughtp = boughtp.front();
	 
		if ( iBoughtn > iSoldn )
 
		{
			//boughtn.changeData( soldn.front() );
			benefit += iSoldn * ( iSoldp - iBoughtp ) ;
		}
 
		else
 
		{
		//	soldn.changeData( boughtn.front() );
			benefit += iBoughtn * ( iSoldp  - iBoughtp ) ;
		}
		cout << "The benefit is " << benefit << endl ;
		 boughtn.pop() ;
	     boughtp.pop() ;
	     soldn.pop() ;
	     soldp.pop() ;
   }
        
   

	return 0;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900