c++ - How to fix an "expected primary-expression" error -
i'm working on project in our programming class requires me make inventory system. there error in code in line 243 gives weird errors when compile it.
line 243 beneath in code is
while(inventory>>rec.prodtype>>rec.menutype>>rec.prodnum
#include<iostream> #include<windows.h> #include<string> #include<fstream> #include<conio.h> #include<stdlib.h> using namespace std; handle console = getstdhandle(std_output_handle); coord cursorposition; void gotoxy(int x, int y); void add(); void view(); void menu(); void types(); void input(); void stock(); void find_name(); void find_number(); void find_type(); void find_mtype(); void all(); void output(); struct inventory{ string prodtype,menutype; string prodnum,prodname; int quantity; float prodprice; }rec; int main() { int x=1,y=1; //for gotoxy char l; //choice determine add/view system("cls"); cout<<"\n\nÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"; cout<<"\t\t\t\t inventory system\n"; cout<<"ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"; cout<<"\n\t\t ---- [1] add new product ----" <<"\n\t\t ---- [2] add stocks existing products ----" <<"\n\t\t ---- [3] view products ----" <<"\n\t\t ---- [4] exit program ----" <<"\n\n\t\t\t\t enter choice : "; back: l=getch(); if(l=='1') add(); else if(l=='2') stock(); else if(l=='3') view(); else if(l=='4') return 0; else goto back; } void stock_intro() { cout<<"\n\nÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"; cout<<"\t\t\t\t adding of stocks\n"; cout<<"ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ\n\n"; } void stock() { string num; //for inputting prodnum... int x; //for adding stocks string prodtype,menutype; string prodnum,prodname; int quantity; float prodprice; ifstream inventory("inventory.txt"); system("cls"); stock_intro(); cout<<"\t\t\t enter product number add stock:\n\n"; cout<<"\t\t\t "; cin>>num; while(inventory>>prodtype>>menutype >>prodnum>>prodname>>quantity >>prodprice){ system("cls"); cout<<"how many stocks add?: "; cin>>x; rec.quantity=rec.quantity+x; } } void types() { ofstream inventory("inventory.txt", ios::app); char c; cout<<"\n\nÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"; cout<<"\t\t\t\tfood , beverages\n"; cout<<"ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ\n"; cout<<"\t\t\t\t [a] snacks\n\t\t\t\t [b] candies\n\t\t\t\t [c] biscuits\n\t\t\t\t [d] chocolates\n\t\t\t\t [e] canned goods\n\t\t\t\t [f] condiments\n\t\t\t\t [g] instant noodles\n\t\t\t\t [h] beverage / drinks\n"; cout<<"\n\t\t\t\t enter choice: "; back: c=getch(); c=toupper(c); if(c=='a') rec.menutype="snacks"; else if(c=='b') rec.menutype="candies"; else if(c=='c') rec.menutype="biscuits"; else if(c=='d') rec.menutype="chocolates"; else if(c=='e') rec.menutype="canned goods"; else if(c=='f') rec.menutype="condiments"; else if(c=='g') rec.menutype="instant noodles"; else if(c=='h') rec.menutype="beverage / drinks"; else goto back; inventory<<rec.menutype; } void input() { system("cls"); cout<<"\n\nÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"; cout<<"\t\t\t\tadding of products\n"; cout<<"ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ\n\n"; ofstream inventory("inventory.txt", ios::app); cout<<"\t\t\tenter product number: "; cin>>rec.prodnum; cout<<"\t\t\tenter product name: "; cin>>rec.prodname; cout<<"\t\t\tenter product price: "; cin>>rec.prodprice; cout<<"\t\t\tenter quantity: "; cin>>rec.quantity; inventory<<endl <<rec.prodnum<<endl <<rec.prodname<<endl <<rec.prodprice<<endl <<rec.quantity<<endl<<endl; } void add() { char c,d; //for choosing food or hygene char e; //for choosing if add of not back2: system("cls"); cout<<"\n\nÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"; cout<<"\t\t\t\t add products\n"; cout<<"ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"; ofstream inventory ("inventory.txt", ios::app); cout<<"\n\n\t\t\t\t[a] food , beverages\n\t\t\t\t[b] hygiene"; cout<<"\n\n\t\t\t\tenter choice: "; back1: c=getch(); d=toupper(c); if(d=='a') rec.prodtype="food & beverages"; else if(d=='b') rec.prodtype="hygiene"; else goto back1; system("cls"); inventory<<rec.prodtype<<endl; types(); input(); cout<<"\n\t\t\tenter product? [y / n]: "; back3: e=getch(); e=toupper(e); if(e=='y') goto back2; else if(e=='n') main(); else goto back3; } void output() { cout<<"product type: " <<rec.prodtype<<endl; cout<<"menu type : " <<rec.menutype<<endl; cout<<" product number: " <<rec.prodnum<<endl; cout<<" product name: " <<rec.prodname<<endl; cout<<" product price: " <<rec.prodprice<<endl; cout<<" stocks available: " <<rec.quantity<<endl; } void view_intro() { system("cls"); cout<<"\n\nÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"; cout<<"\t\t\t\tviewing of inventory\n"; cout<<"ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ\n"; } void view() { char ch; system("cls"); view_intro(); cout<<"\n\t\t ---- [1] find product name ----" <<"\n\t\t ---- [2] find product number ----" <<"\n\t\t ---- [3] find product type ----" <<"\n\t\t ---- [4] find menu type ----" <<"\n\t\t ---- [5] display records ----" <<"\n\n\t\t\t\t enter choice : "; back: ch=getch(); ch=getch(); switch(ch) { case '1': find_name();break; case '2': find_number();break; case '3': find_type();break; case '4': find_mtype();break; case '5': all();break; default: goto back; } } void find_name() { string name; int v=0; system("cls"); view_intro(); ifstream student("record.txt"); cout<<"\n enter product name [incorrect capitalization invalid]: "; cin>>name; system("cls"); view_intro(); while(inventory>>rec.prodtype>>rec.menutype>>rec.prodnum >>rec.prodname>>rec.prodprice>>rec.quantity) { back: while(name==rec.prodname) { output(); break; } v++; if(v<1) { goto back; } } system("pause"); main(); } void gotoxy(int x, int y) { cursorposition.x = x; cursorposition.y = y; setconsolecursorposition(console,cursorposition); }
in find_name() function:
while(inventory>>rec.prodtype>>rec.menutype>>rec.prodnum >>rec.prodname>>rec.prodprice>>rec.quantity) you dont declare inventory in function. did mean open file in variable called inventory did in other functions?
the reason compiler giving weird errors declared type called inventory , not seeing local variable called inventory assumes you're using type makes no sense in context of above line , compiler gets confused , gives obscure error.
Comments
Post a Comment