Hi. I am doing this assignment for my computer science class, and my professor said my answer was "too complicated", so I need to find a simpler solution to it.
The assignment is how to calculate how many 2x2 brownies can fit into a pan of varying sizes. And the brownies need to go in the pan as wholes. For example, for a 1x10 pan the correct answer would be 0, as I can't fit any whole 2x2 brownies into that.
This is what I have at the moment. It gives the correct answer as I used modulus to figure out the "correct" height/length, but as I said - it's too complicated apparently.
#include <iostream>
usingnamespace std;
int main()
{
//Declare variables
int length = 9; //length of a baking pan in inches
int width = 9; //width of a baking pan in inches
int smallBrownies;
int bigBrownies;
//Get the pan dimensions
cout << "Enter the baking pan length (in inches): " << endl;
cin >> length;
cout << "Enter the baking pan width (in inches): " << endl;
cin >> width;
//Compute and assign
smallBrownies = (length * width)/1; //determine how many small brownies pan can hold
bigBrownies = ((width-(width % 2))*(length-(length % 2)))/4;
//Display
cout << "A " << length << " by " << width << " pan can hold " << smallBrownies << " small brownies or " << bigBrownies << " large brownies " << endl;
return 0;
}
Just curious, in lines 8 and 9. Why do you assign the length and width to 9 inches if it is going to be changed by the user in lines 15 and 17? Or am I reading this wrong. If so, sorry, I am new to C++.