Question

In: Computer Science

​​​​​​​in c code Add an intro screen Ask the user for their name, what type of...

​​​​​​​in c code

  • Add an intro screen
  • Ask the user for their name, what type of cookie they would like to order and how many.
  • The types are sugar, chocolate chip, and peanut butter.
  • Assign a cost to each cookie.
  • Show total for cookie purchase and ask if the would like to place another order.
  • Include at least one function and one loop.
  • Add one extra feature.

For example, a sample execution of your code would be as follows:

Cookie Corner! (name it whatever you want)

Please enter your first name.

Jane

Jane, what type of cookie would you like to order?

  1. Sugar - $0. 25
  2. Chocolate Chip - $0.35
  3. Peanut Butter - $0.35

1

You selected a SUGAR cookie. How many cookies would you like?

4

Jane, your total cost is $1.00

Would you like to order another type of cookie?

No

Thanks for ordering!

Solutions

Expert Solution

SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.


#include <stdio.h>
#include<string.h>
double order()
{
double price,cost;
int quantity;
// read the user choice
int choice;
  
// ask user what type of cookie they would like to order and how many.
printf("1. Sugar - $0. 25\n");
printf("2. Chocolate Chip - $0.35\n");
printf("3. Peanut Butter - $0.35\n");
scanf("%d",&choice);
if(choice==1)
{
printf("You selected a SUGAR cookie. How many cookies would you like?\n");
scanf("%d",&quantity);
price=0.25;
}
else if(choice==2)
{
printf("You selected a CHOCLATE cookie. How many cookies would you like?\n");
scanf("%d",&quantity);
price=0.35;
}
else if(choice==3)
{
printf("You selected a PEANUT BUTTER cookie. How many cookies would you like?\n");
scanf("%d",&quantity);
price=0.35;
}
else
{
return -1;
}
// calculate the cost for this cookie
cost=quantity*price;
// return the cost for this item
return cost;
}

int main()
{
// cost and total cost are the double value ex: 1.23, 23.45 etc.,
double cost=0, totalCost=0;

char name[100],yesOrNo[10];
printf("Welcome to Cookie Corner!\n");
// ask name
printf("Please enter your first name:\n");
scanf("%s",name);
while(1)
{
printf("%s, what type of cookie would you like to order?\n",name);
cost=order();
if(cost==-1)
printf("That's a wrong choice. Please try again..");
else
{
printf("%s, your cost for this item is $%.2lf.",name,cost);
// add it to the totalCost
totalCost+=cost;
}
  
// ask for another choclate??
printf("\nWould you like to order another type of cookie? ");
scanf("%s",yesOrNo);
  
if(strcmp(yesOrNo,"No")==0)
{
printf("%s, your total cost is $%.2lf",name,totalCost);
break;
}
}
  
printf("\nThanks for ordering");
  
return 0;
}

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

SCREENSHOT:

OUTPUT:

Welcome to Cookie Corner!
Please enter your first name:
Raju
Raju, what type of cookie would you like to order?
1. Sugar - $0. 25
2. Chocolate Chip - $0.35
3. Peanut Butter - $0.35
1
You selected a SUGAR cookie. How many cookies would you like?
4
Raju, your cost for this item is $1.00.
Would you like to order another type of cookie? yes
Raju, what type of cookie would you like to order?
1. Sugar - $0. 25
2. Chocolate Chip - $0.35
3. Peanut Butter - $0.35
2
You selected a CHOCLATE cookie. How many cookies would you like?
3
Raju, your cost for this item is $1.05.
Would you like to order another type of cookie? yes
Raju, what type of cookie would you like to order?
1. Sugar - $0. 25
2. Chocolate Chip - $0.35
3. Peanut Butter - $0.35
3
You selected a PEANUT BUTTER cookie. How many cookies would you like?
5
Raju, your cost for this item is $1.75.
Would you like to order another type of cookie? yes
Raju, what type of cookie would you like to order?
1. Sugar - $0. 25
2. Chocolate Chip - $0.35
3. Peanut Butter - $0.35
4
That's a wrong choice. Please try again..
Would you like to order another type of cookie? No
Raju, your total cost is $3.80
Thanks for ordering

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


Related Solutions

c++ In this program ask the user what name they prefer for their file, and make...
c++ In this program ask the user what name they prefer for their file, and make a file, the file name should za file. Get a number from the user and save it into the create file. should be more than 20 number in any order. print out all 20 numbers in a sorted array by using for loop, last print out its total and average. At last create a function in which you will call it from main and...
This code needs to be in C++, please. Step 1: Add code to prompt the user...
This code needs to be in C++, please. Step 1: Add code to prompt the user to enter the name of the room that they are entering information for. Validate the input of the name of the room so that an error is shown if the user does not enter a name for the room. The user must be given an unlimited amount of attempts to enter a name for the room. Step 2: Add Input Validation to the code...
Write a C++ code to ask the user to enter 4 values (whole numbers). Your code...
Write a C++ code to ask the user to enter 4 values (whole numbers). Your code should print the numbers in descending order.
Write a program using C language that -ask the user to enter their name or any...
Write a program using C language that -ask the user to enter their name or any other string (must be able to handle multiple word strings) - capture the epoch time in seconds and the corresponding nanoseconds - ask the user to type in again what they entered previously - capture the epoch time in seconds and the corresponding nanoseconds -perform the appropriate mathematical calculations to see how long it took in seconds and nanoseconds (should show to 9 decimal...
Using (C programming language) Create a health monitoring program, that will ask user for their name,...
Using (C programming language) Create a health monitoring program, that will ask user for their name, age, gender, weight, height and other health related questions like blood pressure and etc. Based on the provided information, program will tell user BMI, blood pressure numbers if they fall in healthy range or not and etc. Suggestions can be made as what should be calorie intake per day and the amount of exercise based on user input data. User should be able to...
Write a C++ code to perform the following steps: 1. Ask the user to enter two...
Write a C++ code to perform the following steps: 1. Ask the user to enter two whole numbers number1 and number2 ( Number 1 should be less than Number 2) 2. calculate and print the sum of all even numbers between Number1 and Number2 3. Find and print all even numbers between Number1 and Number2 4. Find and print all odd numbers between Number1 and Number2 5. Calculate and print the numbers and their squares between 2 and 20 (inclusive)...
Write a C++ code to perform the following steps: 1. Ask the user to enter two...
Write a C++ code to perform the following steps: 1. Ask the user to enter two whole numbers number1 and number2 (Number1 should be less than number2) 2. Calculate and print the sum of all even numbers between Number1 and Number2 3. Find and print all even numbers between Number1 and Number2 4. Find and print all odd numbers between Number1 and Number2 5. Calculate and print the numbers and their squares between 1 and 20 (inclusive) 6. Calculate and...
use repil.it intro to C-programin be sure Make code very basic and add good comments thank...
use repil.it intro to C-programin be sure Make code very basic and add good comments thank you 1-Write a program that requests 5 integers from the user and stores them in an array. You may do this with either a for loop OR by getting a string from stdin and using sscanf to store formatted input in each spot in the array. 2-Add a function to the program, called get_mean that determines the mean, which is the average of the...
Create a small program that contains the following. ask the user to input their name ask...
Create a small program that contains the following. ask the user to input their name ask the user to input three numbers check if their first number is between their second and third numbers
Write a c++ program that ask a user to enter his name and birthday (YYYY/MM/DD). If...
Write a c++ program that ask a user to enter his name and birthday (YYYY/MM/DD). If the age is greater than 21 print "welcome," and if the age is less than 21 print "sorry." Use input validation to make sure the birthdate was entered correctly.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT