following code is about adding vehicle details(ID,number,category, brand,price etc.) to a menu and displaying entered details,searching for a particular vehicle based on either vehicle number or category and deleting a record of sold vehicle.
#include<iostream>
usingnamespace std;
struct vehicles
{
char vehicalid[8];
char vehicalnumber[8];
char category[10];
char brand[20];
int price;
} data[100];
int main ()
{
int count=0;
char* point[8];
char num[8];
int option;
int b=0;
int a;
int n=0;
cout<<"option (1) add vehicle details \n";
cout<<"option (2) view view details \n";
cout<<"option (3) search for a vehicle \n";
cout<<"option (4) delete vehicle details \n"<<endl;
loop:
cout<<"option 01 \n"<<endl;
cout<<"enter vehicle ID \t";
cin>>data[n].vehicalid;
cout<<"enter vehicle number \t";
cin>>data[n].vehicalnumber ;
cout<<"enter vehicle category \t";
cin>>data[n].category;
cout<<"enter brand of the vehicle \t";
cin>>data[n].brand;
cout<<"enter price of the vehicle \t";
cin>>data[n].price;
cout<<" Emter your option to continue \t";
cin>>a;
n++;
if(a==1) goto loop;
switch (a){
case 2:
cout<<n;
cout<<endl;
cout<<"option 2 \n"<<'\n';
cout<<"ID \t"<<"Number \t"<<"category \t"<<"brand \t"<<"price \t"<<endl;
while(b<n){
cout<<data[b].vehicalid<<'\t'<<data[b].vehicalnumber<<'\t'<<'\t'<<data[b].category<<'\t'<<data[b].brand <<'\t'<<data[b].price<<endl;
b++;
}
cout<<" Emter your option to continue \t";
cin>>a;
if(a==1) goto loop;
break;
case 3:
cout<<"option (2) \n";
cout<<"search for a vehicle \n";
cout<<"option (1) by number \n";
cout<<"option (2) by category \n";
cin>>option;
if(option==1)
cout<<"enter the number \t";
cin>>num;
*point=data[b].vehicalnumber;
while (*point!=num){
count=count+1;
b++;
}
cout<<data[count].vehicalid <<'\t'<<data[count].vehicalnumber<<'\t'<<data[count].category<<'\t'<<data[count].brand<<'\t'<<data[count].price<<endl;
cout<<" Emter your option to continue \t";
cin>>a;
if(a==1) goto loop;
break;
default:
cout<<"default not done yet";
}
system("pause");
return 0;
}
i 'm stuck at searching for vehicle details by vehicle id
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
case 3:
cout<<"option (2) \n";
cout<<"search for a vehicle \n";
cout<<"option (1) by number \n";
cout<<"option (2) by category \n";
cin>>option;
if(option==1)
cout<<"enter the number \t";
cin>>num;
*point=data[b].vehicalnumber;
while (*point!=num){
count=count+1;
b++;
}
cout<<data[count].vehicalid <<'\t'<<data[count].vehicalnumber<<'\t'<<data[count].category<<'\t'<<data[count].brand<<'\t'<<data[count].price<<endl;
for(int i = 0; i < NUMBER_OF_VEHICLES; i++){
if(strcmp(data[i].vehicalnumber, num)==0) break;
}
now data[i] is the car you want!
Other notes.
Why would you make wehicalnumber a string? the label says NUMBER...
char* point[8]; This creates eight char pointers, while you only need one. (in fact you don't need any at all)
Don't use goto. At least try to avoid them. They make you program harder to understand and debug. There is absolutely no reason why you couldn't use a loop here.
Use std libraries. <string> and <vector> would be useful here.
Try to split your code into functions. Don't put everything into main. Eventually your code will become a mess otherwise.
Declare your variables where you use them. That way it is easier to know what is their type.
Don't system("pause"). See this http://www.cplusplus.com/forum/articles/11153/