Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have the code almost right, I just need it to round to only 2 decimals places & am not sure how to do that

I have the code almost right, I just need it to round to only 2 decimals places & am not sure how to do that in C.image text in transcribedimage text in transcribed

DESCRIPTION A milk carton can hold 3.78 liters of milk. Each morning, a dairy farm ships cartons of milk to a local grocery store. The cost of producing one liter of milk is $0.38, and the profit of each carton of milk is $0.27. Write a program that: 1. Prompts the user to enter the total amount of milk produced in liters. 2. Outputs the number of milk cartons needed to hold milk. 3. Outputs the cost of producing the milk. 4. Outputs the profit from producing the milk. For example (sample user inputs are shown with an underline): Enter, in liters, the total quantity of milk produced: 3.78 The number of milk cartons needed to hold milk: 1 The cost of producing milk: $ 1.44 Profit: $ 0.27 nunc C2.2.c:16:16: warning: incompatible implicit declaration of built-in func tion 'ceil' C2.2.c:16:16: note: include '' or provide a declaration of 'ceil' C2.2.c:7:1: #include 12 6 #include 7 #include 8 9 int main() 10- { 11 double liters; int numCartons; 13 14 printf("Enter, in liters, the total quantity of milk produced: "); scanf("%lf",&liters); 16 17 numCartons=(liters/3.78); 18 19 printf("The number of milk cartons needed to hold milk: %d " , numCartons); C2.2.c:16:16: numCartons ceil(liters/3.78); 15 20 printf("The cost of producing milk: $ %21f ", liters*0.38); printf("Profit: $ %21f ", numCartons*0.27); 21 22 23 24 25 26 27 } return 0; \/tmp/ccZdKhAd.o: In function 'main': C2.2.c:(.text+0x52): undefined reference to ceil' Icollect2: error: ld returned 1 exit status user@mimir: ~/cpsc_1010_all_sections_spring2021/chapterproject_22 > gcc -Wall C2.2.0 \/tmp/ccmLX9Jo.0: In function 'main': C2.2.c:(.text+0x52): undefined reference to ceil' Icollect2: error: ld returned 1 exit status user@mimir: ~/cpsc_1010_all_sections_spring2021/chapterproject_22 > gcc Wall C2.2.c user@mimir: ~/cpsc_1010 all_sections_spring2021/chapterproject_22 > ./a. out Enter, in liters, the total quantity of milk produced: 3.78 The number of milk cartons needed to hold milk: 1 The cost of producing milk: $1.436400 Profit: $0.270000 user@mimir: ~/cpsc_1010_all_sections_spring2021/chapterproject_22 > gcc Wall C2.2.c user@mimir: ~/cpsc_1010 all_sections_spring2021/chapterproject_22 > ./a. out Enter, in liters, the total quantity of milk produced: 5 The number of milk cartons needed to hold milk: 1 The cost of producing milk: $1.900000 Profit: $0.270000 fuser@mimir: ~/cpsc_1010_all_sections_spring2021/chapterproject_22 >

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_2

Step: 3

blur-text-image_3

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

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions