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-
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-