I'm having a compile error, my project is to make a soda machine, complete with 5 dispensers and give change and all that
i was wondering if anyone could help me decipher the error, im completely lost about it
the line in question is
[cout << x << ". " << soda_machine->dispenser[x] << endl;]
x is an int defined in a for loop

78 C:\Users\Owner\Documents\My Received Files\212.01.cpp

[no match for 'operator<<' in 'std::operator<< [with _Traits = std::char_traits<char>](((std::basic_ostream<char, std::char_traits<char> >&)(+(&std::cout)->std::basic_ostream<_CharT, _Traits>::operator<< [with _CharT = char, _Traits = std::char_traits<char>](x))), ((const char*)". ")) << soda_machine->SodaMachine::dispenser[x]' ]

if you need more info about the project, just lemme know
thanks

Member Avatar for jencas

What type has soda_machine->dispenser[x]??? Has it an operator << or a const char * operator?

it has a const char * operator

Can you post some more code, like the definition of soda_machine->dispenser[x], if the code isn't very long, just post it all.

no problem
this is the bases of it

[struct SodaMachine
{
Dispenser dispenser[5];
int quarters, nickels, dimes;
};
void purchase(SodaMachine* soda_machine)
{


int coin;
int total = 0;
int drink;
bool loop = true;


while(loop)
cout << "Please insert\n1. Quarter\n2. Dime\n3. Nickel\n4. Select Drink to Purchase\n";
cin >> coin;
if (coin == 1)
{
soda_machine->quarters++;
total += 25;
}
if (coin == 2)
{
soda_machine->dimes++;
total += 10;
}
if (coin == 3)
{
soda_machine->nickels++;
total += 5;
}
if (coin == 4)
{
loop = false;
}


for (int x=0; x<5; x++)
{
cout << "Please Select the Drink you wish to Purchase\n";
cout << x << ". " << soda_machine->dispenser[x] << endl;
}


cin >> drink;
if (total >= soda_machine->dispenser[drink]->cents)
{
cout << "Thank you for your purchase";
if (total > soda_machine->dispenser[drink]->cents)
{
change(&soda_machine, total, drink);
}
}


else
{
fail(total);
}



}

thats the struct, and function with that im having problems with

whole code is roughly 300 lines idk if i should post all or not

Member Avatar for iamthwee
struct SodaMachine
{
  Dispenser dispenser[5];
  int quarters, nickels, dimes;
};

void purchase ( SodaMachine* soda_machine )
{

  int coin;
  int total = 0;
  int drink;
  bool loop = true;

  while ( loop )
    cout << "Please insert\n1. Quarter\n2. Dime\n3. Nickel\n4. Select Drink to Purchase\n";
  cin >> coin;
  if ( coin == 1 )
  {
    soda_machine->quarters++;
    total += 25;
  }
  if ( coin == 2 )
  {
    soda_machine->dimes++;
    total += 10;
  }
  if ( coin == 3 )
  {
    soda_machine->nickels++;
    total += 5;
  }
  if ( coin == 4 )
  {
    loop = false;
  }

  for ( int x = 0; x < 5; x++ )
  {
    cout << "Please Select the Drink you wish to Purchase\n";
    cout << x << ". " << soda_machine->dispenser[x] << endl;
  }

  cin >> drink;
  if ( total >= soda_machine->dispenser[drink]->cents )
  {
    cout << "Thank you for your purchase";
    if ( total > soda_machine->dispenser[drink]->cents )
    {
      change ( &soda_machine, total, drink );
    }
  }

  else
  {
    fail ( total );
  } 
}

What about Dispenser that must be a struct or something?

yes the dispenser is a struct

[struct Dispenser    // one struct that holds the sodas name, location, and cost
{
int location;
int cents;
string name;
};]

although now i am also having problems with reading from the file and getting a decent number.
i used a switch statement.
if someone could look at it for me that would be great

[void initialize (ifstream& soda, ifstream& coin, SodaMachine* soda_machine)
{
string coin_line;
char coin_type;
char temp_char;
int num_coins;


do
{
//Read in line from file
coin >> coin_type;


//Check to make sure coin_type is a valid type
switch (coin_type)
{
case 'Q':
coin_type = 'q';
break;
case 'q':


coin >> temp_char;
if (temp_char==':')
{
coin >> num_coins;


if (num_coins >= 0)
{
soda_machine->quarters=num_coins;
}
else
{
//num_coins is less than 0 or soda failed
}
}
else
{
//Second character was not a colon
}
break;
case 'D':
coin_type = 'd';
break;
case 'd':


coin >> temp_char;
if (temp_char==':')
{
coin >> num_coins;


if (num_coins >= 0)
{
soda_machine->dimes=num_coins;
}
else
{
//num_coins is less than 0 or soda.cin failed
}
}
else
{
//Second character was not a colon
}
break;
case 'N':
coin_type = 'n';
break;
case 'n':


coin >> temp_char;
if (temp_char==':')
{
coin >> num_coins;


if (num_coins >= 0)
{
soda_machine->nickels=num_coins;
}
else
{
//num_coins is less than 0
}
}
else
{
//Second character was not a colon
}
break;
case '@': //should be default
//First letter in line is not Q, q, D, d, N, or n
break;
}
}
while (coin);
}]
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.