Question

Coffee Order Structure Assignment Write a program that uses a structure for a coffee order. A...

Coffee Order Structure Assignment

Write a program that uses a structure for a coffee order. A coffee order consists of a double price, a string for flavor, and characters for cream (Y/N), sugar (Y/N), and coffee size (S/M/L).

Your main() function will call an order function that will ask the user for the flavor, size and whether or not they want cream or sugar.

Your main() function will then create a coffee order structure and assign all of the values for the coffee order.

Your main() function will then call a display order function that will display the coffee order and the price. A small is $3.00, medium is $4.50, and large is $6.00.

Your order coffee function will contain an array of strings for the available flavors:

char *selectedFlavors[5] = {"House", "Iced", "Vanilla", "Hazelnut", "Mocha"};

Your order coffee function will then ask the user what size of coffee they would like (S/M/L) and validate the data allowing them to continue until they answer with an S, M, or L.

Using your array of strings, display the various available flavors and use an fgets() to get the flavor from the user. You do not need to validate this!

Lastly, ask the user if they would like cream (Y/N) and ask if they would like sugar (Y/N). These do not need to be validated either!

Your display order function must display like one of the following ways based on the order.

In order to make the display order function display the flavor correctly (since you are using the fgets() ), you will have to call this function in your program to remove the enter key from your string:

Homework Answers

Answer #1

#include <stdio.h>
#include<stdbool.h>
struct coffee_order
{
    double price; // variable for price
    char flavor[10]; // string variable to store flavor of coffee 
    char cream; // to store user preference for cream 
    char sugar; // to store user preference for sugar 
    char coffee_size; // to store user choice for size of coffee  
    
};
void order(double *p,char *f,char *c,char *s,char *ch) // function to take udser input
{
    /* we are using pointers so out choices stick even when our function has completed */
    char *selectedFlavors[5] = {"House", "Iced", "Vanilla", "Hazelnut", "Mocha"}; // to store flavors available
    // below do-while will continue to loop until user enters S,M or L 
    
    while(true)
    {
    printf("Enter S for small,M for medium and L for large:");
    scanf(" %c",ch);
    if(*ch=='S' || *ch=='M' || *ch=='L')
    {
        break; // break the loop if user inputs correct choice
    }
    }
    if(*ch=='S')
    {
        *p=3.0;
    }
    else if(*ch=='M')
    {
        *p=4.5;
    }
    else
    {
        *p=6.0;
    }
    // below for loop will display various flavors
    printf("Choose a flavor and type its name:");
    for(int i=0;i<5;i++)
    {
        printf(" %s",selectedFlavors[i]); // to display different flavors 
    }
    printf(":");
    scanf(" "); // to ignore newline
    fgets(f, 10, stdin); // to take input from the user and stores it in f
    printf("\nWould you like cream(Y/N): "); // to output to the screen
    scanf(" %c",c); // to take user input
    printf("\nWould you like sugar(Y/N): "); // to output to the screen
    scanf(" %c",s); // to take user input
    
}
void display(struct coffee_order c)
{
    // displaying all details of coffee order
    printf("Your coffee order is:\n");
    printf("The price for coffee order is $%lf\n",c.price);
    printf("The flavor for coffee order is %s\n",c.flavor);
    printf("The cream for coffee order is %c\n",c.cream);
    printf("The sugar for coffee order is %c\n",c.sugar);
    printf("The coffee size for coffee order is %c\n",c.coffee_size);
    
}
int main()
{
    double p; //  variable for price
    char f[10]; //  variable to store flavor of coffee 
    char c; //  to store user preference for cream 
    char s; //  to store user preference for sugar 
    char ch; //  to store user choice for size of coffee  
    // calling the order function
    order(&p,f,&c,&s,&ch);
    struct coffee_order userOrder; // declaring variable of type coffee_order 
    // populating coffee_order
    userOrder.price=p;
    for(int i=0;i<10;i++)
    {
        userOrder.flavor[i]=f[i];
    }
    userOrder.cream=c;
    userOrder.sugar=s;
    userOrder.coffee_size=ch;
    // calling the display function
    display(userOrder);
    return 0;
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Assignment #4 – Student Ranking : In this assignment you are going to write a program...
Assignment #4 – Student Ranking : In this assignment you are going to write a program that ask user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’...
Write a C program that prompts the user to enter a line of text on the...
Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr and readLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate on NUL-terminated...
In C++ Employee Class Write a class named Employee (see definition below), create an array of...
In C++ Employee Class Write a class named Employee (see definition below), create an array of Employee objects, and process the array using three functions. In main create an array of 100 Employee objects using the default constructor. The program will repeatedly execute four menu items selected by the user, in main: 1) in a function, store in the array of Employee objects the user-entered data shown below (but program to allow an unknown number of objects to be stored,...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF A RUNNING COMPILER QUESTION: 1) Fibonacci sequence is a sequence in which every number after the first two is the sum of the two preceding ones. Write a C++ program that takes a number n from user and populate an array with first n Fibonacci numbers. For example: For n=10 Fibonacci Numbers: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 2): Write...
In this assignment you will write a program that compares the relative strengths of two earthquakes,...
In this assignment you will write a program that compares the relative strengths of two earthquakes, given their magnitudes using the moment magnitude scale. Earthquakes The amount of energy released during an earthquake -- corresponding to the amount of shaking -- is measured using the "moment magnitude scale". We can compare the relative strength of two earthquakes given the magnitudes m1 and m2 using this formula: f=10^1.5(m1−m2) If m1>m2, the resulting value f tells us how many times stronger m1...
Questions: 1. (5 marks) Create a VB.NET Console Application that defines a function Smallest and calls...
Questions: 1. Create a VB.NET Console Application that defines a function Smallest and calls this function from the main program. The function Smallest takes three parameters, all of the Integer data type, and returns the value of the smallest among the three parameters. The main program should (1) Prompt a message (using Console.WriteLine) to ask the user to input three integers. (2) Call the built-in function Console.ReadLine() three times to get the user’s input. (3) Convert the user’s input from...
Please answer in JAVA IDS 401 Assignment 4 Deadline In order to receive full credit, this...
Please answer in JAVA IDS 401 Assignment 4 Deadline In order to receive full credit, this assignment must be submitted by the deadline on Blackboard. Submitting your assignment early is recommended, in case problems arise with the submission process. Late submissions will be accepted (but penalized 10pts for each day late) up to one week after the submission deadline. After that, assignments will not be accepted. Assignment The object of this assignment is to construct a mini-banking system that helps...
MIPS ASSEMBLY Have the user input a string and then be able to make changes to...
MIPS ASSEMBLY Have the user input a string and then be able to make changes to the characters that are in the string until they are ready to stop. We will need to read in several pieces of data from the user, including a string and multiple characters. You can set a maximum size for the user string, however, the specific size of the string can change and you can’t ask them how long the string is (see the sample...
write a program that automates the process of generating the final student report for DC faculty...
write a program that automates the process of generating the final student report for DC faculty considering the following restrictions. Consider declaring three arrays for processing the student data: studID studName studGrade The student ID is a random number generated by the 5-digit system in the range of (10000 - 99999). Create a function to assign the student ID generated in an array of numbers. Consider the following to generate the random number: Add the libraries: #include <stdlib.h> #include <ctime>...
Task 2: Compare strings. Write a function compare_strings() that takes pointers to two strings as inputs...
Task 2: Compare strings. Write a function compare_strings() that takes pointers to two strings as inputs and compares the character by character. If the two strings are exactly same it returns 0, otherwise it returns the difference between the first two dissimilar characters. You are not allowed to use built-in functions (other than strlen()) for this task. The function prototype is given below: int compare_strings(char * str1, char * str2); Task 3: Test if a string is subset of another...