• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

Getting syntax errors

#include <iostream.h>
#include <conio.h>
      
class Inventory
{
      friend ostream &operator<<(ostream &out, const Inventory &re);
      friend istream &operator>>(istream &in, Inventory &re);

private:
      int stockNum;
      int quantity;
      double price;
};
{
      istream operator>>(istream &in, Inventory &item);
      cout<<"Enter Stock number:"endl;
      cin>>itm.stockNum;
      cout<<"Enter Quantity    :"endl;
      cin>>itm.quantity;
      cout<<"Enter Price       :"endl;
      cin>>itm.price;

      if(itm.stockNum < 0||itm.stockNum>999)
            throw("Stock Number out of range ";
      if(itm.quantity < 0)
            throw(itm, quantity);
      if(itm.price > 100.00)
            throw(itm, price);
      return(in);
}

//--------------------------------------------------------------------
void main()
{
      const num=5;
      Inventory anItem[num];
      int x;
      for(x=0,x=num;++x);

      try
      {
            cin>>anItm[x];
      }
      catch (const int quantity)
      {
      cout<<quantity<<" is a negative quantity-that's O.K.">>endl;
      }
      catch (const char *msg)
      {
      cout<<msg<<endl;
      cout<<"Please re-enter"<<endl;
      --x;
      }
      catch (const double pr)
      {
      cout<<"The price "<<pr<< "is too high"<<endl;
      anItm[x], setPriceTo9s();
      cout<<"Price summary "<<endl;
      getch();
      }
0
redice
Asked:
redice
1 Solution
 
hongjunCommented:
you seem to have a lot of undeclared identifiers.
could you post a complete code?

hongjun
0
 
rstaveleyCommented:
This needs fixing:
--------8<--------
{
     istream operator>>(istream &in, Inventory &item);
--------8<--------

You probably want:
--------8<--------
istream operator>>(istream &in, Inventory &item)
{
--------8<--------

You are missing operator<< too.
0
 
rediceAuthor Commented:
#include <iostream.h>
#include <conio.h>
      
class Inventory
{
      friend ostream& operator<<(ostream &out, const Inventory &itm);
      friend istream& operator>>(istream &in, Inventory &itm);

private:
      int stockNum;
      int quantity;
      double price;
};

ostream& operator<<(ostream &out, const Inventory &itm)
{
      out<<"Stock number "<<itm.stockNum <<"Quantity "<<itm.quantity<<"Price "<<itm.price;
      return(out);
}

istream& operator>>(istream &in, Inventory &itm)
{      
      
      cout<<"Enter Stock number:"endl;
      cin>>itm.stockNum;
      cout<<"Enter Quantity    :"endl;
      cin>>itm.quantity;
      cout<<"Enter Price       :"endl;
      cin>>itm.price;

      if(itm.stockNum < 0||itm.stockNum>999)
      
      throw("Stock Number out of range ";

      if(itm.quantity < 0)
      
            throw(itm.quantity);
      
      if(itm.price > 100.00)
      
            throw(itm.price);
      
      return(in);
}

//--------------------------------------------------------------------
void main()
{
      const num=5;
      Inventory anItem[num];
      int x;
      for(x=0,x<num;++x);
      {
      try
      {
            cin>>anItm[x];
      }
      catch (const int quantity)
      {
      cout<<quantity<<" is a negative quantity-that's O.K.">>endl;
      }
      catch (const char *msg)
      {
      cout<<msg<<endl;
      cout<<"Please re-enter"<<endl;
      --x;
      }
      catch (const double pr)
      {
      cout<<"The price "<<pr<< "is too high"<<endl;
      anItm[x], setPriceTo9s();
      cout<<"Price summary "<<endl;
      getch();
      }

//This is more like it ... sorry
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
tinchosCommented:
Hi redice

I have compiled your code and corrected several errors (marked with error here)

I have one error left which is almost at the end of the code

setPriceTo9s is undefined, I'm not sure what you meant.

Here's the corrected code..........

#include <iostream.h>
#include <conio.h>
   
class Inventory
{
    friend ostream& operator<<(ostream &out, const Inventory &itm);
    friend istream& operator>>(istream &in, Inventory &itm);

private:
    int stockNum;
    int quantity;
    double price;
};

ostream& operator<<(ostream &out, const Inventory &itm)
{
    out<<"Stock number "<<itm.stockNum <<"Quantity "<<itm.quantity<<"Price "<<itm.price;
    return(out);
}

istream& operator>>(istream &in, Inventory &itm)
{    
     
    cout<<"Enter Stock number:" << endl;  // Error here
    cin>>itm.stockNum;
    cout<<"Enter Quantity    :" << endl;  // Error here
    cin>>itm.quantity;
    cout<<"Enter Price       :" << endl;  // Error here
    cin>>itm.price;

    if(itm.stockNum < 0||itm.stockNum>999)
   
     throw("Stock Number out of range ");   // Error here

    if(itm.quantity < 0)
   
          throw(itm.quantity);
   
     if(itm.price > 100.00)
   
          throw(itm.price);
   
     return(in);
}

//--------------------------------------------------------------------
void main()
{
    const num=5;
    Inventory anItem[num];
    int x;
    for(x=0;x<num;++x);   // Error here
    {
    try
    {
         cin>>anItem[x];   // Error here
    }
    catch (const int quantity)
    {
    cout<<quantity<<" is a negative quantity-that's O.K."<<endl;  // Error here
    }
    catch (const char *msg)
    {
    cout<<msg<<endl;
    cout<<"Please re-enter"<<endl;
    --x;
    }
    catch (const double pr)
    {
    cout<<"The price "<<pr<< "is too high"<<endl;
    anItem[x].setPriceTo9s();                // Error still here: Dont know what setPriceTo9s is
    cout<<"Price summary "<<endl;
    getch();
}

Hope it helps

Tincho
0
 
rediceAuthor Commented:
Thanks. I appreciate it.
0
 
DanRollinsCommented:
redice,
The best way to thank an Expert here is to click the [Accept] button next to his comment.  You currently have asked four questions and not closed any of them.  Please read:  http:/help.jsp#hs5
-- Dan Rollins, EE Page Editor
0
 
migoEXCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept tinchos's comment as answer.

Please leave any comments here within the next four days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

migoEX
EE Cleanup Volunteer
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now