|
-
April 26th, 2010, 08:18 AM
#1
Help with my program
Weee almost finish this program but one last thing. Why does this program crash whenever i quit after i do something to the records . Somebody please compile the program and try it and please tell me what is the problem. And guys try deleting the data then view them. Whats the prob??(ignore the #)
#
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
struct weapon
{
string id;
string name;
string quantity;
};
int choice(weapon add[],int size);
weapon view(weapon add[],int size);
weapon deleting( weapon add[], int size);
weapon modify( weapon add[],int size);
int choice(weapon add[],int size)
{
int again;
int option;
cout<< "1: Delete weapon \n";
cout<< "2: Modify records \n";
cout<< "3: View records\n";
cout<< "4: Exit \n" ;
cin>> option;
switch(option)
{
case 1 eleting(add,size); break;
case 2:modify(add,size);break;
case 3:view( add,size); break;
case 4:again=2; break;
}
cout<<again;
return again;
}
//DELETING FUNCTION
weapon deleting( weapon add[], int size)
{
string weapon_id;
cout<< "Enter the id of teh weapon you wanna delete."<< endl;
cin>> weapon_id;
int b=0;
bool out=true;
//QUERY
int a;
for ( a=0; a<size|| out; a++)
{
if (add[a].id==weapon_id)
{
cout<< setw(15)<< add[a].id<< " "<<add[a].name<< " "<<add[a].quantity<< endl;
cout<< "This is teh weapon you wanna delete at row "<< a << endl;
out=false;
b=a;
}
}
//DELETING DATA
int n;
for( n=b; n<size; n++)
{
if((n+1)<size)
add[n]=add[n+1];
}
choice(add,size);
}
//MODIFYING DATA
weapon modify(weapon add[],int size)
{
string weapon_id;
cout<< "Enter the id of teh weapon you wanna modify."<< endl;
cin>> weapon_id;
int b=0;
bool out=true;
//QUERY
int a;
for ( a=0; a<size|| out; a++)
{
if (add[a].id==weapon_id)
{
cout<< setw(15)<< add[a].id<< " "<<add[a].name<< " "<<add[a].quantity<< endl;
cout<< "This is teh weapon you wanna delete at row "<< a << endl;
out=false;
b=a;
}
}
cout<<"Enter the new id"<< endl;
cin>> add[b].id;
cout<<"Enter the new name"<< endl;
cin>> add[b].name;
cout<<"Enter the new quantity"<< endl;
cin>> add[b].quantity;
choice(add,size);
}
//VIEWING WEAPON
weapon view(weapon add[],int size)
{
cout<<setw(15)<< "Weapon id" <<" "<<setw(15)<<"Weapon_name" <<" " <<setw(15)<< "Weapon Quantity"<< endl;
for(int l=0; l<size;l++)
{
cout<<setw(15)<< add[l].id<<" "<<setw(15)<< add[l].name<<setw(15)<<add[l].quantity<< endl;
}
choice(add,size);
}
int main()
{
cout<< "First, you gotta insert the records first"<< endl;
int i,k,size,l;
i=1;
l=0;
k=1;
cout<< "Enter size of record"<< endl;
cin>> size;
weapon add[ size];
for( l=0; l<size;l++)
{
cout<<"Enter the id"<< endl;
cin>> add[l].id;
cout<<"Enter the name"<< endl;
cin>> add[l].name;
cout<<"Enter the quantity"<< endl;
cin>> add[l].quantity;
}
int again=1;
while (again==1)
{
again=choice(add,size);
}
return 0;
}
#
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|