Please help me simplify my code!

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.

Any suggestions? :/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>

using namespace 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++.
That's only there because I ran it through http://www.compileonline.com/compile_cpp_online.php to test it out.

Also nevermind, I'm retarded. Figured it out by myself.

bigBrownies = (width/2) * (length/2);

So simple. T_T
Topic archived. No new replies allowed.