Hi all i have a problem here in my program it is already complete it's a grocery program... I have 4 index and i want to add something there but if the index reaches 5 when i choose add again it must say there is no more space because i only have a max of 4 index.. here is my program..
Code:
#include <iostream>
#include <conio.h>
#include <string>
#include <stdlib.h>
using namespace std;
struct grocery{
char product[10], item_name[10], mfg[10], exp[10], price[10], ava[10], descp[30];
}pro[4];
main(){
int n=0;
int ch, num, in;
int a=0;
do{
cout <<"1. Add\n" <<"2. Delete\n"<<"3. List\n"<<"4. Edit\n" <<"5. Exit\n";
cout <<"Choice: ";
cin >> ch;
switch(ch){
case 1:
cout <<"==============\n\n";
cout<<"Index # " << a+1;
cout<<"\nProduct = ";
cin>> pro[a].product;
cout<<"\nItem name = ";
cin>> pro[a].item_name;
cout<<"\nMfg Date = ";
cin>> pro[a].mfg;
cout<<"\nExp Date = ";
cin>> pro[a].exp;
cout<<"\nPrice = ";
cin>> pro[a].price;
cout<<"\nAvailability = ";
cin>> pro[a].ava;
cout<<"\nDescription = ";
cin>> pro[a].descp;
a++;
break;
case 2:
cout <<"Please wait...\n";
cout <<"Complete!!!\n";
for (int b=0; b<=3; b++){
strcpy(pro[b].product, " ");
strcpy(pro[b].item_name, " ");
strcpy(pro[b].mfg, " ");
strcpy(pro[b].exp, " ");
strcpy(pro[b].price, " ");
strcpy(pro[b].ava, " ");
strcpy(pro[b].descp, " ");
cout << endl;
}break;
case 3: for (int c=0; c<=3; c++){
cout <<"==============\n";
cout <<"Index # " << c+1;
cout <<"\n";
cout <<"Product = "<< pro[c].product << "\n";
cout <<"item name = "<< pro[c].item_name <<"\n";
cout <<"Mfg Date = "<< pro[c].mfg << "\n";
cout <<"Exp Date = "<< pro[c].exp << "\n";
cout <<"Price = "<< pro[c].item_name <<"\n";
cout <<"Availability = "<< pro[c].mfg << "\n";
cout <<"Description = "<< pro[c].exp << "\n";
cout <<endl;
}break;
case 4: cout << "index to edit: ";
cin>> in;
if (in>=5){
cout <<"no such index!!!\n";
cout <<"EXITING...";
getch();
exit(1);
}
else{
for (int d=in; d<=in; d++){
cout<<"\nProduct: ";
cin>> pro[d].product;
cout<<"\nItem name: ";
cin>> pro[d].item_name;
cout<<"\nMfg Date: ";
cin>> pro[d].mfg;
cout<<"\nExp Date: ";
cin>> pro[d].exp;
cout <<"\n";
}
}break;
case 5: exit(1);
}
}while(n==0);
getch();
}
anyone?... and about in list... for example i have added a data at index 1 so index is not empty and i have not yet added any data at index 2, 3 and 4 so it must say when i pick on list the data that i have added in index 1 will show up while index 2, 3 and 4 have no entry so it will say at index 2,3 and 4 empty.. hope you understand me tnx..