#Use mathematical expression and operator priority correctly.

52 messages · Page 1 of 1 (latest)

fiery ether
#

Prompt: Dough hydration is the water/flour ratio of the dough in grams. Neapolitan-style pizza typically has a hydration level of around 65%. Given the int variables called flourWeight and waterWeight, which contain the corresponding integer numbers, please calculate the value of the corresponding hydration and store it in the float flourHydration variable, which has already been declared. Be mindful of the fact that a fractional result is expected.

Issue: I keep getting an logic error and I really cannot see where I'm going wrong.

The check solution box states: The resulting value is not correct. Are you sure to have performed the correct calculation? you should multiply the flower weight by the hydration percentage, which has been divided by 100

Desired input is 0.8 but I'm getting 3.25 as an output.

Code:

flourHydration = static_cast<float>(flourWeight) * (0.65 / 100)
small hawkBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

lone canopy
#

When in doubt, add brackerts and let your IDE tell you which brackets can be removed

fiery ether
#

add brackets to what

lone canopy
#

Around parts of the operation to force a specific order

#

Also keep a lookout for integer didivion that will drop decimals but from your example it seems fine

fiery ether
#

around the 0.65 and 100?

lone canopy
#

Just general advice, I didn't look too much into your assignment

fiery ether
#

I know but the brackets around the 0.65 and the 100 gave me a compile error

lone canopy
#

0.65/100 doesn't seem like a good way of representing 65%

#

Either 65/100.f or 0.65 not both

fiery ether
#

it's not supposed to represent 65%

#

the 0.65 represents the 65% and I'm dividing by 100 because that is what the program is asking

#

and I've also tried flourweight * 0.65

#

which yields an output of 325

lone canopy
#

Given the int variables called flourWeight and waterWeighyou should be using waterWeight somewhere

#

65% seems to just be an example of an ideal result

fiery ether
#

hmm

lone canopy
#

The check is weird though, you should multiply the flower weight by the hydration percentage, which has been divided by 100 the assignment suggests flourHudration is itself the percentage to calculate

fiery ether
#

I tried this

flourHydration = static_cast<float>(waterWeight) / flourWeight * 100;
#

and the output was 80

#

closer

#

I'm assuming I have to convert both waterWeight and flourWeight to float

#

to display a float

oak trench
#

you should

fiery ether
#

but that would still yield 8.0 I think

lone canopy
#

static_cast<float>(waterWeight) / flourWeight woul be the ratio if 0.8 is the expected you should just not multiply by 100

oak trench
#

that's because the percentage is the water weight divided by the total weight

#

your mathematical logic is wrong

fiery ether
#

so how do I fix it

oak trench
#

if you had equal parts water and flour, you'd expect the water percentage to be 50% but yor formula will yield 100% for this

fiery ether
#

because I'm multiplying by 100

oak trench
#

no

lone canopy
#

ngl the assignment is a bit strange

oak trench
#

multiplying by 100 is correct, you are dividing by the wrong thing

#

yeah i agree both as a programmer and a former doughmaster

fiery ether
#

yeah these assignments suck

#

but why did I get the right answer by just using static_cast<float>(waterWeight) / flourWeight

#

and not multiplying by 100

lone canopy
#

It should be something like static_cast<float>(waterWeight) / (waterWeight + flourWeight)

fiery ether
#

odd

#

well I mean it works

#

I have another assignment posted on here and I need help with that one as well becuase I feel like the program does not explain the concepts well

#

or the directions per say

lone canopy
#

You should bring it up with your professor that really seems like an error

fiery ether
#

!solved

small hawkBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

lone canopy
#

@fiery ether can you link the other thread?