Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The code I developed is as follows: #define _CRT_SECURE_NO_WARNINGS #include int main(void) { char coffeeType1, coffeeType2, coffeeType3, creamServed1, creamServed2, creamServed3,

imageimageimageimage

The code I developed is as follows:

#define _CRT_SECURE_NO_WARNINGS

 

#include

 

int main(void)

{

    char coffeeType1, coffeeType2, coffeeType3, creamServed1, creamServed2, creamServed3,

        coffeeStrength, noCream;

    int packageWeight1, packageWeight2, packageWeight3, dailyServings;

 

    // You will need this when converting from grams to pounds (lbs)

    const double GRAMS_IN_LBS = 453.5924;

 

    printf("Take a Break - Coffee Shop\n\n\n");

    printf("==========================\n\n");

    printf("Enter the coffee product information being sold today...\n\n");

    printf("COFFEE-1...\n");

    printf("Type ([L]ight,[M]edium,[R]ich): ");

    scanf(" %c", &coffeeType1);

    printf("\n");

    printf("Bag weight (g): ");

    scanf(" %d", &packageWeight1);

    printf("\n");

    printf("Best served with cream ([Y]es,[N]o): ");

    scanf(" %c", &creamServed1);

 

    printf("\n\n");

    printf("COFFEE-2...\n");

    printf("Type ([L]ight,[M]edium,[R]ich): ");

    scanf(" %c", &coffeeType2);

    printf("\n");

    printf("Bag weight (g): ");

    scanf(" %d", &packageWeight2);

    printf("\n");

    printf("Best served with cream ([Y]es,[N]o): ");

    scanf(" %c", &creamServed2);

 

    printf("\n\n");

    printf("COFFEE-3...\n");

    printf("Type ([L]ight,[M]edium,[R]ich): ");

    scanf(" %c", &coffeeType3);

    printf("\n");

    printf("Bag weight (g): ");

    scanf(" %d", &packageWeight3);

    printf("\n");

    printf("Best served with cream ([Y]es,[N]o): ");

    scanf(" %c", &creamServed3);

 

    printf("\n\n");

    printf("---+------------------------+---------------+-------+\n");

    printf("   | Coffee                 | Packaged      | Best  |\n");

    printf("   | Type                   | Bag Weight    | Served|\n");

    printf("   +------------------------+---------------+ With  |\n");

    printf("ID | Light | Medium | Rich  | (G) | Lbs     | Cream |\n");

    printf("---+------------------------+---------------+-------|\n");

    printf(" 1 |   %d  |   %d   |   %d  | %4d | %6.3lf  |   %d  |\n",

        (coffeeType1 == 'l' || coffeeType1 == 'L'),

        (coffeeType1 == 'r' || coffeeType1 == 'R'),

        (coffeeType1 == 'm' || coffeeType1 == 'M'),

        packageWeight1, packageWeight1 / GRAMS_IN_LBS,

        (creamServed1 == 'y' || creamServed1 == 'Y'));

    printf(" 2 |   %d  |   %d   |   %d  | %4d | %6.3lf  |   %d  |\n",

        (coffeeType2 == 'l' || coffeeType2 == 'L'),

        (coffeeType2 == 'm' || coffeeType2 == 'M'),

        (coffeeType2 == 'r' || coffeeType2 == 'R'),

        packageWeight2, packageWeight2 / GRAMS_IN_LBS,

        (creamServed2 == 'y' || creamServed2 == 'Y'));

    printf(" 3 |   %d  |   %d   |   %d  | %4d | %6.3lf  |   %d  |\n",

        (coffeeType3 == 'l' || coffeeType3 == 'L'),

        (coffeeType3 == 'm' || coffeeType3 == 'M'),

        (coffeeType3 == 'r' || coffeeType3 == 'R'),

        packageWeight3, packageWeight3 / GRAMS_IN_LBS,

        (creamServed3 == 'y' || creamServed3 == 'Y'));

 

    printf("\n\n");

    printf("Enter how you like your coffee...\n\n");

    printf("Coffee strength ([L]ight, [M]edium, [R]ich): ");

    scanf(" %c", &coffeeStrength);

    printf("\n");

    printf("Do you like your coffee with cream ([Y]es,[N]o): ");

    scanf(" %c", &noCream);

    printf("\n");

    printf("Typical number of daily servings: ");

    scanf(" %d", &dailyServings);

    

    printf("\n\n");

    printf("The below table shows how your preferences align to the available products:\n\n");

    printf("--------------------+-------------+-------+\n");

    printf("  |    Coffee       |  Packaged   | With  |\n");

    printf("ID|     Type        | Bag Weight  | Cream |\n");

    printf("--+-----------------+-------------+-------+\n");

    printf(" 1|       %d        |      %d     |   %d  |\n",

        (coffeeStrength == 'l' || coffeeStrength == 'L'),

        (dailyServings >= 1 && dailyServings <= 4),

        (noCream == 'y' || noCream == 'Y'));

    printf(" 2|       %d        |      %d     |   %d  |\n",

        (coffeeStrength == 'm' || coffeeStrength == 'M'),

        (dailyServings >= 5 && dailyServings <= 9),

        (noCream == 'n' || noCream == 'N'));

    printf(" 3|       %d        |      %d     |   %d  |\n",

        (coffeeStrength == 'r' || coffeeStrength == 'R'),

        (dailyServings >= 10),

        (noCream == 'y' || noCream == 'Y'));

 

    printf("\n\n");

    printf("Enter how you like your coffee...\n\n");

    printf("Coffee strength ([L]ight, [M]edium, [R]ich): ");

    scanf(" %c", &coffeeStrength);

    printf("\n");

    printf("Do you like your coffee with cream ([Y]es,[N]o): ");

    scanf(" %c", &noCream);

    printf("\n");

    printf("Typical number of daily servings: ");

    scanf(" %d", &dailyServings);

 

    printf("\n");

    printf("The below table shows how your preferences align to the available products:\n\n");

    printf("--------------------+-------------+-------+\n");

    printf("  |    Coffee       |  Packaged   | With  |\n");

    printf("ID|     Type        | Bag Weight  | Cream |\n");

    printf("--+-----------------+-------------+-------+\n");

    printf(" 1|       %d        |      %d     |   %d  |\n",

        (coffeeStrength == 'l' || coffeeStrength == 'L'),

        (dailyServings >= 1 && dailyServings <= 4),

        (noCream == 'y' || noCream == 'Y'));

    printf(" 2|       %d        |      %d     |   %d  |\n",

        (coffeeStrength == 'm' || coffeeStrength == 'M'),

        (dailyServings >= 5 && dailyServings <= 9),

        (noCream == 'n' || noCream == 'N'));

    printf(" 3|       %d        |      %d     |   %d  |\n",

        (coffeeStrength == 'r' || coffeeStrength == 'R'),

        (dailyServings >= 10),

        (noCream == 'y' || noCream == 'Y'));

 

    printf("\n\n");

    printf("Hope you found a product that suits your likes!");

 

    return 0;

}

 

but when run, the values don't match to the output example provided.

3. This program can be broken down into a few major logical code sections: a) Variable declarations: All variables should be declared together into meaningful groups at the top of the main function b) Product data input: Prompt for data describing three (3) products and store user-input to appropriate variables c) Display product data: Summarize the product data in a tabular format to help make the data easy to read d) Customer preference input (2 times): Prompt for the user's coffee preferences and store user-inputs to appropriate variables e) Display summary of results: Apply the customer-input preferences; match how each product meets the needs of the customer defined preferences f) Repeat: Repeat step (d) and (e) for another preference scenario 4. Don't delete or modify the provided "GRAMS_IN_LBS" variable declaration (you will need this in the conversion from grams to pounds when appropriate). 5. Using the example output as a guide, declare the necessary nine (9) variables used to represent the three (3) product data "records". Note You must select the appropriate data type for each variable based on the type of data that needs to be stored You must use self-describing variable name to maximize readability and maintainability of the code 6. Prompting user-input for a single-character value can cause unexpected behaviour which you will learn about later in the semester, however, for now use the following scanf formatting specifier (between the double-quotes) to avoid strange behaviour (notably the single-space before the percent sign): scanf("c", ... 7. Displaying the product data in a tabular format requires the application of some slightly more advanced formatting features (you will learn more about this later in the semester). For now, use the printf statement provided as a comment in the supplied starter w3p2.c file that will look like the below: printf("1 | %d I %d I %d | %4d | $6.31f | %d | ", 8. The below table provides the mapping rules you must apply in matching the customer input preferences to each product (Example: if the user prefers "Light" coffee, and the product type is "Light" this would show as true (1) in the summary table result): Customer Preference Coffee Strength (I or L) (m or M) (r or R) Daily Servings (inclusive range) Light Medium Rich 1 to 4 5 to 9 10 or more Like Groom with Coffee Coffee Type (1 or L) (m or M) (r or R) Coffee Package Weight Light Medium Rich Product 250 g 500 g 1000 g Support Sending with Gramm

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

C++ Primer Plus

Authors: Stephen Prata

6th Edition

978-0321776402, 0321776402

More Books

Students also viewed these Algorithms questions