Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Syntax Error (missing ;)

Status
Not open for further replies.

joesq

Technical User
Oct 27, 2006
2
US
I'm working on a program and have been getting a syntax error I can't seem to fix. The error is:
syntax error : missing ';' before identifier 'inventory'
I had a similar error on another section of the program, and someone suggested that I fix it by using "std::string" in place of "string"...this resolved my problem at the time, but it has not resolved the error here. Below is the code:
------------------------------------------------------
#include <iostream>
#include <string>
#include <vector>
#include "inventory.h"
using namespace std;

theInventory inventory;
void displayMenu();
void enterNewItem();
void removeItem();
void itemInfo();
void changeItemNum();

int main()
{
int menuSelection, exitValue = 0;
while(exitValue!=1)
{
displayMenu();
cin>>menuSelection;
cin.clear();
switch(menuSelection)
{
Case 1:
enterNewItem();
break;
Case 2:
removeItem();
break;
Case 3:
itemInfo();
break;
Case 4:
changeItemNum();
break;
Case 5:
exitValue=1;
break;
Default:
cout<<"You have made an invalid selection. Please re-enter: ";
}
}
return 0;
}

void displayMenu()
{
cout<<endl<<endl<<" ACME Toy & Apparel Company"<<endl<<
" Inventory Control System"<<endl<<endl<<
"1. Enter new Item to the System"<<endl<<
"2. Remove an Item from the System"<<endl<<
"3. Search Item Information"<<endl<<
"4. Change the Item Inventory Number"<<endl<<
"5. Exit the System"<<endl<<endl;

}
void enterNewItem()
{
char itemType;
long invNumber;
string itemDecription, shelfOrRackNumber, categoryOrMaterial;
int qtyInHand;

cout<<"Item type : ";
while( ((itemType = cin.get()) != "T") && ((itemType) != "A") )
cout<<"You have entered an invalid Item Type. Please re-enter: ";
cout<<"Inventory Number : ";
cin>>invNumber;
while( (invNumber < 0) && (invNumber > 99999999) )
{
cout<<"You have entered an invalid Inventory Number. Please re-enter: ";
cin>>invNumber;
}
cout<<"Item Description : ";
cin.get(itemDescription, 40);
cout<<"Shelf Number : ";
cin.get(shelfOrRackNumber, 14);
while(shelfOrRackNumber.length() < 2)
{
cout<<"Please use a longer number: ";
cin.get(shelfOrRackNumber, 14);
}
cout<<"Qty : ";
cin>>qtyInHand;
while( (qtyInHand < 0) && (qtyInHand > 9999) )
{
cout<<"You have entered an invalid Quantity. Please re-enter: ";
cin>>qtyInHand;
}
cout<<"Category/Material : ";
cin.get(categoryOrMaterial, 40);

if (inventory.isExists(invNumber))
{
cout<<"I'm sorry, but that item already exists in the inventory.";
return;
}
inventory.addItem(itemType,invNumber,itemDescription,qtyInHand,
categoryOrMaterial,ShelfOrRackNumber);
}
void removeItem()
{
char yesOrNo;
long invNumber;
int exitValue = 0;

cout<<"Inventory Number : ";
while( ((invNumber = cin.get()) < 0) && ((invNumber) > 99999999) )
cout<<"You have entered an invalid Inventory Number. Please re-enter: ";
cout<<"Are you sure you want to proceed? y/n> ";
while(exitValue==0)
{
if( (yesOrNo=cin.get())!="y")
{
if(yesOrNo!="n")
{
cout<<"You have made an invalid selection. Please enter a 'y' or a 'n': ";
continue;
}
}
else
{
if(inventory.removeItem(invNumber)) //item exists in inventory
cout<<"Item Deleted";
else
cout<<"Item Could not be found"; //item does not exist in inventory
}
exitvalue = 1;
}
}
void itemInfo()
{
long invNumber;

cout<<"Inventory Number : ";
while( ((invNumber = cin.get()) < 0) && ((invNumber) > 99999999) )
cout<<"You have entered an invalid Inventory Number. Please re-enter: ";
if(inventory.isExists(invNumber)!=1)
cout<<"I'm sorry, but that item does not exist in the inventory.";
else
inventory.displayItemInfor(invNumber);
}
void changeItemNum()
{
long invNumber;
long newInvNumber;

cout<<"Inventory Number : ";
while( ((invNumber = cin.get()) < 0) && ((invNumber) > 99999999) )
cout<<"You have entered an invalid Inventory Number. Please re-enter: ";
if(inventory.isExists(invNumber)!=1)
{
cout<<"I'm sorry, but that item does not exist in the inventory.";
return;
}
cout<<"New Inventory Number : ";
while( ((NewInvNumber = cin.get()) < 0) && ((NewInvNumber) > 99999999) )
cout<<"You have entered an invalid Inventory Number. Please re-enter: ";
if(inventory.isExists(newInvNumber))
cout<<"I'm sorry, but that item already exists in the inventory.";
else
inventory.changeInvNumber(invNumber,newInvNumber);
}
-----------------------------------------------------

Thank you for any advice you can offer.

-Joe-
 
Please use [ignore]
Code:
[/ignore] tags when posting code.
It would help if you pointed out which lines you're getting the errors on.

Just a guess, but shouldn't
Code:
theInventory inventory;
be:
Code:
inventory theInventory;

Also, adding some spaces in your code would make it much more readable.
 
Here is a snippet from the build log:
-------------------------------------------
Compiling...
inventory.cpp
driver.cpp
.\driver.cpp(7) : error C2146: syntax error : missing ';' before identifier 'inventory'
.\driver.cpp(7) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\driver.cpp(7) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\driver.cpp(43) : error C2059: syntax error : 'return'
.\driver.cpp(44) : error C2059: syntax error : '}'
.\driver.cpp(44) : error C2143: syntax error : missing ';' before '}'
.\driver.cpp(44) : error C2059: syntax error : '}'
Generating Code...
----------------------------------------------------

Oddly enough, the inventory line is correct....

-----------------------------------------------

I think I just realized the problem...I was trying to build the entire solution, and I haven't completed the "inventory.h" file...if I comment that line, the error dissapears...

Thank you very much for your help; I see the error now.
I guess this is what happens when you write code after 3 AM...

-Joe-
 
But since the file is called "inventory.h", I'm assuming you have a class in there defined as:
Code:
class inventory
{
   ...
};

So when you create your inventory variable, it should be declared as:
Code:
inventory theInventory;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top