Solved

Getting syntax errors

Posted on 2003-12-04
8
249 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

910 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

19 Experts available now in Live!

Get 1:1 Help Now