Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Objectives 1. To reinforce basic programming constructs 2. To learn how to use f

ID: 3790224 • Letter: O

Question

Objectives 1. To reinforce basic programming constructs 2. To learn how to use for loops

Introduction: Ninja Academy Ninjas are awesome! Your friend has not stopped talking about how cool ninjas and how they would like to become a ninja. To amuse your friend, you have decided to create a series of programs about ninjas.

Problem: Ninja Tactics Now that your friend is one the path to becoming a ninja, it’s time for them to learn about some of the sneaky tactics that ninjas employ.

This particular ninja academy prefer non-lethal tactics whenever possible. Apprentice ninjas will need to learn about smoke bombs, sleeping drugs, and first aid. The best way to learn about these things is by examining their ingredients.

Your mentor has tasked you with going to several different stores to place orders. This program should ask for the total number of shops that will be visited. At each shop, ask for the number of ingredients that need to be purchases. For each ingredient, ask for the price. Keep track of the total for the order so that you can write it down before leaving the shop. This program should also track with order was the cheapest and which shop the cheapest order was at. This will help your mentor decide who to keep doing business with!

Input Specification 1. The number of shops will be a positive integer. 2. The number of ingredients will be a positive integer. 3. The cost for each ingredient will be a positive real number.

Output Specification Output the cost at each shop to two decimal places.

Your total at #Y is $X.XX.

At the end of the program, print the cheapest order.

Your cheapest order was at shop #Y and cost $X.XX.

Output Sample Below are some sample outputs of running the program. Note that these samples are NOT a comprehensive test. You should test your program with different data than is shown here based on the specifications given above. In the sample run below, for clarity and ease of reading, the
2
user input is given in italics while the program output is in bold. (Note: When you actually run your program no bold or italics should appear at all. These are simply used in this description for clarity’s sake.)

Sample Run How many shops will you be visiting? 3

You are at shop #1. How many ingredients do you need at shop #1? 2

How much is ingredient #1? 3.5 How much is ingredient #2? 10

Your total at shop #1 is $13.50.

You are at shop #2. How many ingredients do you need at shop #2? 3

How much is ingredient #1? 2.75 How much is ingredient #2? 3 How much is ingredient #3? 1.25

Your total at shop #2 is $7.00.

You are at shop #3. How many ingredients do you need at shop #3? 2

How much is ingredient #1? 4 How much is ingredient #2? 5

Your total at shop #3 is $9.00.

Your cheapest order was at shop #2 and cost $7.00.

Deliverables One source files – ninjatactics.c – is to be submitted over WebCourses.

3
Restrictions Although you may use other compilers, your program must compile and run using Code::Blocks. Your program should include a header comment with the following information: your name, course number, section number, assignment title, and date. Also, make sure you include comments throughout your code describing the major steps in solving the problem.


Grading Details Your programs will be graded upon the following criteria:

1) Your correctness

2) Your programming style and use of white space. Even if you have a plan and your program works perfectly, if your programming style is poor or your use of white space is poor, you could get 10% or 15% deducted from your grade.

3) Compatibility – You must submit C source files that can be compiled and executed in a standard C Development Environment. If your program does not compile, you will get a sizable deduction from your grade.

Please don't answer this with arrays or functions we have not learned that yet. Also I have almost answered this myself but I found the lowest total but I just cannot figure out how to reference the store that has the lowest total. If anyone could explain this to me please I will be most thankful.

Explanation / Answer

#include<stdio.h>

int main(int argc, char const *argv[])
{
   printf("How many shops will you visiting? ");
   int shops;
   scanf("%d",&shops);
   int cheap_shop=9999;
   float cheap_price=9999;
int i;
   for ( i = 0; i < shops; ++i)
   {
       printf("You are at shop #%d ",i+1);
       printf(" How many ingredients do you need at shop #%d? ",i+1 );
       int ingredients;
       scanf("%d",&ingredients);
       float price=0;
       float shop_total=0;
       int j ;
       for ( j = 0; j < ingredients; ++j)
       {
           printf("How much is ingredient #%d? ",j+1 );
           scanf("%f",&price);
          
           shop_total+=price;


       }

       if(shop_total<cheap_price)
           {
               cheap_price=shop_total;
               cheap_shop=i+1;
           }

       printf("Your total at shop #%d is $%f. ", i+1,shop_total);

   }
   printf("Your cheapest order was at shop #%d and cost $%f. ",cheap_shop,cheap_price );
   return 0;
}

=====================================================================================

Output:

akshay@akshay-Inspiron-3537:~/Chegg$ gcc shpos.c
akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
How many shops will you visiting?
3
You are at shop #1
How many ingredients do you need at shop #1?
2
How much is ingredient #1?
3.5
How much is ingredient #2?
10
Your total at shop #1 is $13.500000.
You are at shop #2
How many ingredients do you need at shop #2?
3
How much is ingredient #1?
2.75
How much is ingredient #2?
3
How much is ingredient #3?
1.25
Your total at shop #2 is $7.000000.
You are at shop #3
How many ingredients do you need at shop #3?
2
How much is ingredient #1?
4
How much is ingredient #2?
5
Your total at shop #3 is $9.000000.
Your cheapest order was at shop #2 and cost $7.000000.