Issue with "illegal else without matching if"

Hi. I am doing this assignment for my computer science class and I can't figure out what the problem is. It is giving me "error C2181: illegal else without matching if" when trying to execute it in visual studio. I can't figure out why, because as far as I know there is not even any 'if' statement in there.

Thanks in advance for any help!

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
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>

using namespace std;

int main()
{
   //Declare variables
   int length = 0;  //length of a baking pan in inches
   int width = 0;   //width of a baking pan in inches
   int area;
   int smallBrownies;
   int bigBrownies;
   int panModW;
   int panModL;
   int pandimW;
   int pandimL;
   
   //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
   panModW=width % 2; // lazy conditional (will always be 1)
   panModL=length % 2; // lazy conditional (will always be 1)
   pandimW=width-panModW; //calculate "correct" width
   pandimL=length-panModL; //calculate "correct" length
   area = length * width;
   smallBrownies = area/1;  //determine how many small brownies pan can hold
   bigBrownies =((pandimW*pandimL)/4);    //determine how many big brownies pan can hold

   
   //Display
   cout << "A " << length << " by " << width << " pan can hold " << smallBrownies << " small brownies or " << bigBrownies << " large brownies " << endl;
   
   return 0;
}
Actually rewrote and simplified it to this and it runs fine now. However I'm wondering if there's an easier way to do the calculations for bigBrownies? I'm using modulus to turn the potential odd numbers in width/length into even numbers, since the odd numbers are excess space. (bigBrownies are 2x2 in size, and can only go into the pan as wholes.)

Sorry for the short explanation and if it's too vague.

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;
}
Topic archived. No new replies allowed.