added calling purchase function
This commit is contained in:
parent
2656180e25
commit
b6b164f434
27
vendorInfo.c
27
vendorInfo.c
|
@ -86,7 +86,6 @@ int main()
|
|||
}
|
||||
|
||||
char user_query[100];
|
||||
read_input(user_query, 100);
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
@ -95,7 +94,9 @@ int main()
|
|||
break;
|
||||
}
|
||||
|
||||
printf("What do you want to buy? (DONE to end) ");
|
||||
read_input(user_query, 100);
|
||||
|
||||
// convert string to lowercase - each character one by one
|
||||
int user_query_length = strlen(user_query);
|
||||
for (int i = 0; i < user_query_length; i++)
|
||||
|
@ -103,7 +104,28 @@ int main()
|
|||
user_query[i] = tolower(user_query[i]);
|
||||
};
|
||||
|
||||
search(user_query, vendors, total_vendors);
|
||||
int result = search(user_query, vendors, total_vendors);
|
||||
if(result > 0)
|
||||
{
|
||||
int item_amount;
|
||||
|
||||
char input[10];
|
||||
read_input(input, 10);
|
||||
|
||||
if(atoi(input) < 0)
|
||||
{
|
||||
item_amount = atoi(input);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("You must enter a positive whole number for the number of items");
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("No vendor in this market sells %s\n", user_query);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
@ -185,6 +207,7 @@ int purchase(int item_id, int amount, struct vendor_item vendors[MAX_VENDORS])
|
|||
if(amount <= vendors[item_id].inventory_count)
|
||||
{
|
||||
vendors[item_id].inventory_count = vendors[item_id].inventory_count - amount;
|
||||
|
||||
return vendors[item_id].inventory_count;
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue