⚡ C Programming 🔥 Ninja's Shopping #tecqmate

#include<stdio.h>

void main(){
	int shops;
	printf("How many shops will you be visiting? ");
	fflush(stdin);
	scanf("%d", &shops);
	int inds, shop;
	float cost, sum, min = 0.0f;
	for(int i = 1, j; shops >= i; i++){
		printf("You are at shop #%d. How many ingredients do you need at shop #%d? ", i, i);
		scanf("%d", &inds);
		sum = 0.0f;
		for(j = 1; inds >= j; j ++){
			printf("How much is ingredient #%d? ", j);
			scanf("%f", &cost);
			sum += cost;
		}
		if(1 == i || min > sum){
			min = sum;
			shop = i;
		}
		printf("Your total at shop #%d is $%.2f.\n", i, sum);
	}
	printf("Your cheapest order was at shop #%d and cost $%.2f.\n", shop, min);
}

Comments

Popular posts from this blog