-
simple Struct question
here is the code:
struct SalesItem
{
char upc;
string name;
}
SalesItem itemList[NUM_ITEMS];
get_item_name(itemList, upc);
In the function call for get_item_name I pass the value of upc which can be a char A through I. I am supposed to retrieve the matching name (each value of upc has a corresponding name) and print it. So, itemList[0].upc has value 'A' and itemList[0].name has value "corn", and itemList[1].upc is 'B' and itemList[1].name is "candy", and so on. Is this a possible operation with this type of setup? This code is what our professor gave us to start with.
-
I doubt your professor would give an assignment that wasn't possible. If you look at the data structure you know that when you find one item you also have found the other.
-
update
I do not have the index number to the array. I only have the value of the char upc, and with that need to match up the value of "name" and print it. If I knew what index in the array the specific upc was at it would be easy.
-
Your task is to find the name when given the upc both of which are stored in the same struct you have an array of structures essentailly a list what would you do with a list? If you had a list on paper you would scan each entry looking for the one that matched right? so go through the list compareing each entry to the one you want to find and when you find it output the name.
-
manofSteel
thank you sir, i think that will help me a great deal!