Question

For my project, I have all the calculations correct but for the one part where you...

For my project, I have all the calculations correct but for the one part where you have to calculate the percentages used and wasted it always gives either 0% or a something along the lines of 1000%. How do I correct this?

Code

-----------------------------------------------------------------------------------------------

print ("Welcome to the Cake Slice Program!")
cake_type = str(input("What kind of cake did you make?"))
length = int(input(" How long is the cake in centimeters?"))
width = int(input(" How wide is the cake in centimeters?"))
length_cut = int(input(" How long will you cut your slices in centimeters?"))
width_cut = int(input(" How wide will you cut your slices in centimeters?"))
#-------------------------------------------------------------
###Calculations
#Area's
surface_area = (length*width)
length_area = (length//length_cut)
width_area = (width//width_cut)
slice_area = (length_cut*width_cut)
#
slice_amount = round((length_area)*(width_area),0)
slice_total = (length_cut*width_cut*slice_amount)
slice_waste = (surface_area-slice_total)
slice_total_area = (slice_total*slice_area)
slice_waste_area = (slice_waste*slice_area)
slice_total_percentage = round((slice_total_area//surface_area),0) #percentage calculation
slice_waste_percentage = round((slice_waste_area//surface_area),0) #percentage calculation
total_pieces = (length_area*width_area)
edge_pieces = (2*length_area + 2*(width_area-2))
center_pieces = (total_pieces-edge_pieces)
#-------------------------------------------------------------
###Converting from Integers to String
l_c = str(length_cut)
w_c = str(width_cut)
su_a = str(surface_area)
sl_a = str(slice_amount)
s_t = str(slice_total)
s_t_p = str(slice_total_percentage)
s_w = str(slice_waste)
s_w_p = str(slice_waste_percentage)
e_p = str(edge_pieces)
c_p = str(center_pieces)
#-------------------------------------------------------------
###Outputs for program
print (" Your cake has a surface area of",su_a,"square centimeters.")
print ("You can cut",sl_a,"total",l_c+"x"+w_c,"slices of cake.")
print ("These slice dimensions can cut a total of",s_t,"square centimeters, or",s_t_p+"%, of the cake.")
print ("These slice dimensions will waste",s_w,"square centimeters, or",s_w_p+"%, of the cake.")
print ("There will be",e_p,"edge pieces, and",c_p,"center pieces of cake.")
print ("Enjoy your",cake_type,"cake!")

Homework Answers

Answer #1

Hi,

I've tested the code and it is working as expected, it is giving expected result, find the sample output below.

Suspecting that round() function causing the problem, or the division operation.

So took the input as float instead of string,

please find the working code below

#-----------------------------------------------------------------------------------------------
print ("Welcome to the Cake Slice Program!")
cake_type = str(input("What kind of cake did you make?"))
length = float(input(" How long is the cake in centimeters?"))
width = float(input(" How wide is the cake in centimeters?"))
length_cut = float(input(" How long will you cut your slices in centimeters?"))
width_cut = float(input(" How wide will you cut your slices in centimeters?"))
#-------------------------------------------------------------
###Calculations
#Area's
surface_area = (length*width)
length_area = (length//length_cut)
width_area = (width//width_cut)
slice_area = (length_cut*width_cut)
#
slice_amount = round((length_area)*(width_area),0)
slice_total = (length_cut*width_cut*slice_amount)
slice_waste = (surface_area-slice_total)
slice_total_area = (slice_total*slice_area)
slice_waste_area = (slice_waste*slice_area)
slice_total_percentage = round((slice_total_area//surface_area),0) #percentage calculation
slice_waste_percentage = round((slice_waste_area//surface_area),0) #percentage calculation
total_pieces = (length_area*width_area)
edge_pieces = (2*length_area + 2*(width_area-2))
center_pieces = (total_pieces-edge_pieces)
#-------------------------------------------------------------
###Converting from Integers to String
l_c = str(int(length_cut))
w_c = str(int(width_cut))
su_a = str(int(surface_area))
sl_a = str(int(slice_amount))
s_t = str(int(slice_total))
s_t_p = str(slice_total_percentage)
s_w = str(slice_waste)
s_w_p = str(slice_waste_percentage)
e_p = str(edge_pieces)
c_p = str(center_pieces)
#-------------------------------------------------------------
###Outputs for program
print (" Your cake has a surface area of",su_a,"square centimeters.")
print ("You can cut",sl_a,"total",l_c+"x"+w_c,"slices of cake.")
print ("These slice dimensions can cut a total of",s_t,"square centimeters, or",s_t_p+"%, of the cake.")
print ("These slice dimensions will waste",s_w,"square centimeters, or",s_w_p+"%, of the cake.")
print ("There will be",e_p,"edge pieces, and",c_p,"center pieces of cake.")
print ("Enjoy your",cake_type,"cake!")

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
This is a program and my solution. How many times should I test, if I need...
This is a program and my solution. How many times should I test, if I need full coverage of all possible program flows?  Why? Write a program that prompts the user for a grade (0-100) and, whether the student is a graduate student (Y/N). If the student is a graduate student, their grade is reduced by 10%, because we have a higher expectation for a graduate students in an undergraduate class. The program then computes and prints the letter grade is...
Leave comments on code describing what does what Objectives: 1. To introduce pointer variables and their...
Leave comments on code describing what does what Objectives: 1. To introduce pointer variables and their relationship with arrays 2. To introduce the dereferencing operator 3. To introduce the concept of dynamic memory allocation A distinction must always be made between a memory location’s address and the data stored at that location. In this lab, we will look at addresses of variables and at special variables, called pointers, which hold these addresses. The address of a variable is given by...
If you cant answer this please dont waste my question. thank you. This cryptographic program run...
If you cant answer this please dont waste my question. thank you. This cryptographic program run and produce text screen output. You are to create a GUI that uses the program. Your program (GUI) must allow a user to input of a message to be coded. It must also have an area to show the plaintext, the ciphertext, and the decrypted text. If required by your choice of cryptographic method, the user should have an area to input a key....
Homework Draw class diagrams for your HW4 - the Tetris Game shown below: Part 1: UML...
Homework Draw class diagrams for your HW4 - the Tetris Game shown below: Part 1: UML As a review, Here are some links to some explanations of UML diagrams if you need them. • https://courses.cs.washington.edu/courses/cse403/11sp/lectures/lecture08-uml1.pdf (Links to an external site.) • http://creately.com/blog/diagrams/class-diagram-relationships/ (Links to an external site.) • http://www.cs.bsu.edu/homepages/pvg/misc/uml/ (Links to an external site.) However you ended up creating the UML from HW4, your class diagram probably had some or all of these features: • Class variables: names, types, and...
I have the following program which returns F(n) for the fibonacci sequence both recursively and iteratively:...
I have the following program which returns F(n) for the fibonacci sequence both recursively and iteratively: public class Fibonacci { //Recursive method public int fibRecursive(int n) { //If n is in the 0th or 1st place return n if (n <= 1) return n; return fibRecursive(n - 1) + fibRecursive(n - 2); } //Iterative method public int fibIterative(int n) { if (n <= 1) return n; int fib = 1, prevFib = 1; for (int i = 2; i <...
[PART ONE OF PROJECT, ALREADY COMPLETED] An accumulator is a primitive kind of calculator that can...
[PART ONE OF PROJECT, ALREADY COMPLETED] An accumulator is a primitive kind of calculator that can evaluate arithmetic expressions. In fact, the Arithmetic-Logic Unit (ALU) of the rst computers was just an accumulator. An arithmetic expression, as you know, consists of two kinds of tokens: operands and operators All our operands will be (float) numbers and for a start, we shall use only two operators: + (plus) and - (minus) A sample run of the program would look like this....
MATH125: Unit 1 Individual Project Answer Form Mathematical Modeling and Problem Solving ALL questions below regarding...
MATH125: Unit 1 Individual Project Answer Form Mathematical Modeling and Problem Solving ALL questions below regarding SENDING A PACKAGE and PAINTING A BEDROOM must be answered. Show ALL step-by-step calculations, round all of your final answers correctly, and include the units of measurement. Submit this modified Answer Form in the Unit 1 IP Submissions area. All commonly used formulas for geometric objects are really mathematical models of the characteristics of physical objects. For example, a basketball, because it is a...
You can complete this assignment individually or as a group of two people. In this assignment...
You can complete this assignment individually or as a group of two people. In this assignment you will create a ​​Sorted Singly-Linked List​ that performs basic list operations using C++. This linked list should not allow duplicate elements. Elements of the list should be of type ‘ItemType’. ‘ItemType’ class should have a private integer variable with the name ‘value’. Elements in the linked list should be sorted in the ascending order according to this ‘value’ variable. You should create a...
I was asked to write a program in CodeBlocks. C++ format. I've written the first half...
I was asked to write a program in CodeBlocks. C++ format. I've written the first half of the code but I am using else and if statements. I feel like the code is too long to do a simple calculation. In CodeBlock when you build and run your code, a new terminal window opens (in windows a new console window) and you can enter your inputs there. It is not like eclipse that you enter your inputs in console view....
Description: The purpose of this assignment is to practice writing code that calls functions, and contains...
Description: The purpose of this assignment is to practice writing code that calls functions, and contains loops and branches. You will create a C program that prints a menu and takes user choices as input. The user will make choices regarding different "geometric shapes" that will be printed to the screen. General Comments: Your code must contain at least one of all of the following control types: nested for() loops a while() or a do-while() loop a switch() statement an...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT