variables always not declared: so really confused!!
Mar 17, 2013 at 8:30am UTC
this is my code for the inventory system i am trying to code and it always says
D:\Users\uzer\Documents\CB\dawd\prototype.cpp||In function 'int main()':|
D:\Users\uzer\Documents\CB\dawd\prototype.cpp|170|error: 'addrec' was not declared in this scope|
D:\Users\uzer\Documents\CB\dawd\prototype.cpp|177|error: 'change_rec' was not declared in this scope|
D:\Users\uzer\Documents\CB\dawd\prototype.cpp|184|error: 'disp_rec' was not declared in this scope|
D:\Users\uzer\Documents\CB\dawd\prototype.cpp|191|error: 'isave' was not declared in this scope|
D:\Users\uzer\Documents\CB\dawd\prototype.cpp|199|error: 'del_rec' was not declared in this scope|
||=== Build finished: 5 errors, 0 warnings (0 minutes, 0 seconds) ===|
pls help me???...
code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
#include<iostream>
#include<conio.h>
#include<cstring>
#include<fstream>
#include<iomanip>
#include<cctype>
using namespace std;
class inventory
{
private :
char item_name[20];
int serial_code[20];
float cost[20];
float qty[20];
public :
void addrec();
void change_rec();
void disp_rec();
void isave();
void del_rec();
int rec;
};
// \\==========================ADD RECORD=========================//
void inventory::addrec()
{
cout<<"\t\t=========================\t\t" <<endl;
cout<<"\t\t || ADD RECORD || \t\t" <<endl;
cout<<"\t\t=========================\t\t" <<endl;
cout<<"----------------------------------------------" ;
cout<<"\t\tENTER DETAILS TO BE RECORDED\t\t" <<endl;
cout<<"----------------------------------------------" ;
cout<<"\t\tPRODUCT NAME : \t\t" ;
cin>>item_name[rec];
cout<<"\t\tSERIAL CODE : \t\t" ;
cin>>serial_code[rec];
cout<<"\t\tQUANTITY : \t\t" ;
cin>>qty[rec];
cout<<"\t\tCOST : \t\t" ;
cin>>cost[rec];
rec++;
}
// \\=======================EDIT RECORD=========================//
void inventory::change_rec()
{
char item_name[20];
int serial_code[20];
float cost[20];
float qty[20];
int i;
cout<<"\t\t============================" ;
cout<<"\t\t|ENTER PRODUCT SERIAL CODE| " ;
cout<<"\t\t============================" ;
cout<<"SERIAL CODE:# " ;
cin>>serial_code[i];
for (i = 0; i < rec; i++)
{
if (serial_code[i] == 0)
{
cout<<"========================================" <<endl;
cout<<"Enter New Product Name: " <<item_name[i]<<endl;
cout<<"Enter New Serial Code: " <<serial_code[i]<<endl;
cout<<"Enter New Cost: " <<cost[i]<<endl;
cout<<"Enter New Quantity: " <<qty[i]<<endl;
cout<<"========================================" <<endl;
break ;
}
}
if (i == rec)
{
cout<<"Record not found?" <<endl;
}
}
// \\===============DISPLAY RECORD BOOK===============//
void inventory::disp_rec()
{
int i;
for (i = 0; i < rec; i++)
{
cout<<"=========PRODUCT INFORMATION========" ;
cout<<"\t\tPRODUCT NAME : \t\t" ;
cout<<item_name[i]<<endl;
cout<<"\t\tSERIAL CODE : \t\t" ;
cout<<serial_code[i]<<endl;
cout<<"\t\tQUANTITY : \t\t" ;
cout<<qty[i]<<endl;
cout<<"\t\tCOST : \t\t" ;
cout<<cost[i]<<endl;
}
}
// \\====================SAVE RECORD=================//
void inventory::isave()
{
ofstream save_rec;
save_rec.open("recordbook.txt" );
save_rec.close ();
};
// \\====================Delete Record================//
void inventory::del_rec ()
{
int i, d;
cout<<"\nPlease enter the item code:" ;
cin>>i;
for (d=0;d<i;d++)
{
if (serial_code[d]==i)
{
serial_code[d]=0;
cout<<"\nThe item is deleted from the list." ;
break ;
}
}
}
// \\=====================MENU OPTIONS===================//
int main ()
{
int option;
while (option != 6)
{
cout<<"\t\t=================OPTIONS============" <<endl;
cout<<"\t\t~~~ Option 1 = ADD RECORD~~~" <<endl;
cout<<"\t\t~~~ Option 2 = CHANGE RECORD~~~" <<endl;
cout<<"\t\t~~~ Option 3 = DISPLAY RECORD~~~" <<endl;
cout<<"\t\t~~~ Option 4 = SAVE RECORD~~~" <<endl;
cout<<"\t\t~~~ Option 5 = DELETE RECORD ~~~" <<endl;
cout<<"\t\t====================================" <<endl;
cout<<"\t\tENTER CHOICE: " <<endl;
cin>>option;
switch (option)
{
case 1:
{
addrec();
}
break ;
case 2:
{
change_rec();
}
break ;
case 3:
{
disp_rec();
}
break ;
case 4:
{
isave();
}
break ;
case 5:
{
del_rec();
}
break ;
case 6:
{
}
break ;
default :
{
cout<<"Option unknown!" ;
}
}
}
cin.get();
return 0;
};
Last edited on Mar 17, 2013 at 8:54am UTC
Mar 17, 2013 at 9:12am UTC
addrec and the other functions are member functions of class inventory, so to call the function you need an inventory object.
1 2 3 4 5
// Create the inventory object somewhere at the start of you main function.
inventory inv;
// To call addrec() on the inventory object.
inv.addrec();
Last edited on Mar 17, 2013 at 9:13am UTC
Mar 18, 2013 at 1:15pm UTC
thanks peter87!!!! my system finally run but something is wrong again with my code.....when i chose number 1(enter product name)and try to input details it always jumped to "cost" im having alot of trouble finding out the problem..it seems to be endless.............
anyone can tell me how to correct this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
#include<iostream>
#include<conio.h>
#include<cstring>
#include<fstream>
#include<iomanip>
#include<cctype>
using namespace std;
class inventory
{
private :
char item_name[20];
int serial_code[20]; // declaration of variables
float cost[20];
float qty[20];
float invent[50];
public :
void addrec();
void change_rec();
void disp_rec();
void isave();
void del_rec();
int rec;
};
// \\==========================ADD RECORD=========================//
void inventory::addrec()
{
char item_name[20];
int serial_code[20];
float cost[20];
float qty[20];
cout<<"===================" ;
cout<<"|| ADD RECORD ||" ;
cout<<"===================" ;
cout<<"\n\n-----------------------------" ;
cout<<"\n\nENTER DETAILS TO BE RECORDED" ;
cout<<"\n\n-----------------------------\n" ;
cout<<"PRODUCT NAME : " ;
cin>>item_name[rec];
cout<<"SERIAL CODE : \n" ;
cin>>serial_code[rec];
cout<<"QUANTITY : \n" ;
cin>>qty[rec];
cout<<"COST : " ;
cin>>cost[rec];
rec = rec + 1;
cin.ignore ();
};
// \\=======================EDIT RECORD=========================//
void inventory::change_rec()
{
char item_name[20];
int serial_code[20];
float cost[20];
float qty[20];
int i;
cout<<"============================\n" ;
cout<<"|ENTER PRODUCT SERIAL CODE| \n" ;
cout<<"============================\n" ;
cout<<"SERIAL CODE:# " ;
cin>>serial_code[i];
for (i = 0; i < rec; i++)
{
if (serial_code[i] == 0)
{
cout<<"========================================" ;
cout<<"Enter New Product Name: " <<item_name[i]<<endl;
cout<<"Enter New Serial Code: " <<serial_code[i]<<endl;
cout<<"Enter New Cost: " <<cost[i]<<endl;
cout<<"Enter New Quantity: " <<qty[i]<<endl;
cout<<"========================================" ;
break ;
}
}
if (i == rec)
{
cout<<"Record not found?" <<endl;
}
getch();
};
// \\===============DISPLAY RECORD BOOK===============//
void inventory::disp_rec()
{
int i;
for (i = 0; i < rec; i++)
{
cout<<"=========PRODUCT INFORMATION========" ;
cout<<"PRODUCT NAME : \n" ;
cout<<item_name[i];
cout<<"SERIAL CODE : \n" ;
cout<<serial_code[i];
cout<<"QUANTITY : \n" ;
cout<<qty[i];
cout<<"tCOST : \n" ;
cout<<cost[i];
}
getch();
};
// \\====================SAVE RECORD=================//
void inventory::isave()
{
ofstream save_rec;
save_rec.open("recordbook.txt" );
save_rec.close ();
};
// \\====================Delete Record================//
void inventory::del_rec ()
{
int i, d;
cout<<"\nPlease enter the item code: " ;
cin>>i;
for (d = 0;d < i;d++)
{
if (serial_code[d]==i)
{
serial_code[d]=0;
cout<<"\nThe item is deleted from the list." ;
break ;
}
}
getch();
};
// \\=====================MENU OPTIONS===================//
int main ()
{
inventory inv;
int option;
while (option != 6)
{
cout<<"\t\t=================OPTIONS============\n" ;
cout<<"\t\t ~~~ Option 1 = ADD RECORD ~~~\n" ;
cout<<"\t\t ~~~ Option 2 = CHANGE RECORD ~~~\n" ;
cout<<"\t\t ~~~ Option 3 = DISPLAY RECORD ~~~\n" ;
cout<<"\t\t ~~~ Option 4 = SAVE RECORD ~~~\n" ;
cout<<"\t\t ~~~ Option 5 = DELETE RECORD ~~~\n" ;
cout<<"\t\t====================================\n" ;
cout<<"ENTER CHOICE: " ;
cin>>option;
switch (option)
{
case 1:
{
inv.addrec();
}
break ;
case 2:
{
inv.change_rec();
}
break ;
case 3:
{
inv.disp_rec();
}
break ;
case 4:
{
inv.isave();
}
break ;
case 5:
{
inv.del_rec();
}
break ;
case 6:
{
}
break ;
default :
{
cout<<"Option unknown!" ;
}
break ;
}
getch();
}
cin.get();
return 0;
}
Last edited on Mar 18, 2013 at 1:17pm UTC
Topic archived. No new replies allowed.