Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- /* Logan Teixeira
- * February 11, 2016
- * This program tracks your purchases at each shop and then calculates your cheapest purchase of the day. */
- //Main Function
- int main() {
- //defining variables
- int shops, i, j, ingredients, cheap_shop;
- float price = 0, total = 0, cheap_cost = 0;
- //User input for the number of shops
- printf("How many shops will you be visiting?\n");
- scanf ("%d", &shops);
- //beginning of for loop
- for (i = 1; i<= shops; i++) {
- //need to reset the value of total back to 0
- total = 0;
- printf("\nYou are at shop #%d.\n", i);
- printf("How many ingredients do you need at shop #%d?\n", i);
- scanf ("%d", &ingredients);
- for (j = 1; j <= ingredients; j++){
- //printf("How many ingredients do you need at shop #%d?\n", i);
- printf("How much is ingredient #%d?\n", j);
- scanf ("%f", &price);
- total += price;
- }//end of first loop
- printf("\nYour total at shop #%d is $%.2f\n", i, total);
- }//end of for loop
- //Scan for the cheapest purchase
- printf("Your cheapest order was at shop #%d and cost $%.2f", cheap_shop, cheap_price);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement