-
inventory program
ok here's the deal i have to make a prog that ask the user how many cars that they want to enter, then prompt them for the make, model, year, color, price. Then sorts the info anyway the user wants it. So here's the problem, what do i have to do to make the program get the information and then store it so that i can sort it. I have to do this using structures, but i can't figure it out. i just need someone to point me in the right direction.
any help would be great
thanks
--ManicC--
-
Have you got some code you can post? you really should have a go yourself first as people here will be reluctant to help otherwise.
-
well see that's the problem is i have a lot of code that wasn't even close to right. I'm not asking for anyone to give me code i just needed any ideas as to how i should go about doing this.
this was my idea, but it's doesn't seem very efficient.
do all i need is one stucture then, just ask for input, then assign the input to a struture variable. but then do assign that input to an array so that i can sort it. i don't know i'm lost on this one.
-
first define your structure.
Code:
struct car{
char make[12];
char model[12];
int year;
char color[12];
float price;
};
now you need to declare an array of the above type
Code:
struct car car_array[MAX];
This gives you an array of MAX number of your structure
now you can get input from user
Code:
for(int i=0; i<MAX; i++)
{
printf("\nEnter car make: ");
fgets(car_array[i].make, sizeof(make)-1, stdin);
/* code for rest of input */
}
now you can sort the array, what are you sorting by, make, model etc
-
as for sorting algorithms... look out for quick / merge / shell [my personal favorite] / bubble... etc...
-
Hey thanks a lot C_Coder, i really wasn't expecting that much of a detailed reply. By the way yes, i'm sorting according to make, model, etc. using a bubble sort.
again thanks
--ManicC--