Solved

Getting syntax errors

Posted on 2003-12-04
8
246 Views
Last Modified: 2010-04-02
#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
Comment
Question by:redice
8 Comments
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
you seem to have a lot of undeclared identifiers.
could you post a complete code?

hongjun
0
 
LVL 17

Expert Comment

by:rstaveley
Comment Utility
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
 

Author Comment

by:redice
Comment Utility
#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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 9

Accepted Solution

by:
tinchos earned 250 total points
Comment Utility
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
 

Author Comment

by:redice
Comment Utility
Thanks. I appreciate it.
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
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
 
LVL 5

Expert Comment

by:migoEX
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now