Solved

Getting syntax errors

Posted on 2003-12-04
8
255 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
ID: 9874117
you seem to have a lot of undeclared identifiers.
could you post a complete code?

hongjun
0
 
LVL 17

Expert Comment

by:rstaveley
ID: 9874303
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
ID: 9874317
#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
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!

 
LVL 9

Accepted Solution

by:
tinchos earned 250 total points
ID: 9874623
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
ID: 9874800
Thanks. I appreciate it.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 9878846
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
ID: 10364874
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Writing a parser for java language 4 91
c++ reading data from file into two dimensional array 3 129
DCT of  2D array using fftw in c++ 9 88
boost::uuid crashes 17 36
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

713 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