Advertisement
Guest User

project4

a guest
Feb 11th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.25 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. /* Logan Teixeira
  4.  * February 11, 2016
  5.  * This program tracks your purchases at each shop and then calculates your cheapest purchase of the day. */
  6.  
  7.  //Main Function
  8. int main() {
  9.     //defining variables
  10.     int shops, i, j, ingredients, cheap_shop;
  11.     float price = 0, total = 0, cheap_cost = 0;
  12.     //User input for the number of shops
  13.     printf("How many shops will you be visiting?\n");
  14.     scanf ("%d", &shops);
  15.     //beginning of for loop
  16.     for (i = 1; i<= shops; i++) {
  17.         //need to reset the value of total back to 0
  18.         total = 0;
  19.         printf("\nYou are at shop #%d.\n", i);
  20.         printf("How many ingredients do you need at shop #%d?\n", i);
  21.         scanf ("%d", &ingredients);
  22.         for (j = 1; j <= ingredients; j++){
  23.             //printf("How many ingredients do you need at shop #%d?\n", i);
  24.             printf("How much is ingredient #%d?\n", j);
  25.             scanf ("%f", &price);
  26.             total += price;
  27.         }//end of first loop
  28.         printf("\nYour total at shop #%d is $%.2f\n", i, total);
  29.     }//end of for loop
  30.     //Scan for the cheapest purchase
  31.    
  32.     printf("Your cheapest order was at shop #%d and cost $%.2f", cheap_shop, cheap_price);
  33.  
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement