Solved

Getting syntax errors

Posted on 2003-12-04
8
258 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Socket Programming (Unix) 8 160
Least Squares Curve Fitting 4 133
Add values of each row in an array 3 80
DCT of  2D array using fftw in c++ 9 132
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

732 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