Hello, all. I am relatively new to coding (and this forum!) and trying to code something where the user is going to several shops and buying ingredients for recipes. The user inputs the amount of shops they want to go to, the amount of ingredients they buy at each shop, and the price of each ingredient. Where I am struggling though is the end, I am trying to print the shop number with the lowest total cost and I just can't seem to figure it out. I'll post the code I have so far.
Code:
#include <stdio.h>
int main() {
//variable declaration
int shops, i, j, ing, min_shop = 0;
float price, min_cost = 0, total = 0;
//ask about # of shops
printf("Your mentor has tasked you with going to several different stores to place orders.\n");
printf("How many shops will you be visiting?\n");
scanf(" %d", &shops);
min_shop = shops
//ask about # of ingredients
for(i = 1; i <= shops; i++){
printf("You are at shop #%d.\n", i);
printf("How many ingredients do you need at shop #%d?\n", i);
scanf(" %d", &ing);
//ask about price of ingredients
for(j = 1; j <= ing; j++){
printf("How much is ingredient %d?\n", j);
scanf(" %f", &price);
total = total + price;
min_cost = total
}
//total cost at each shop
printf("Your total at shop number %d is $%.2f.\n", i, total);
}
if (min_cost<total)
printf("Your cheapest order was at shop #%d and cost $%.2f.\n", min_cost, );
return 0;
}
This is what I have so far, obviously it is not perfect by any means lol but any help regarding calculating the cheapest order and printing which shop it was at would be immensely helpful. Thanks so much!