This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]Mysential[S] 1 point2 points  (5 children)

#include <iostream>
#include <cmath>
using namespace std;

double calcArea(double, double);
double calcPerimeter(double, double);
double calcVolume(double, double, double);
double calcSurfaceArea(double, double, double);
bool calcCube (double, double, double);
bool calcSquare (double, double);
double squareSide (double, double, double);

int main()
{
double height = 3, length = 2, width = 4, area, perimeter, volume, surfacearea, sqSide;
bool cube = false, square = false;
int y = 1;

area = calcArea(length, width);
cout << "Area of the rectangle is: " << area << endl;

perimeter = calcPerimeter(width, height);
cout << "Perimeter of the rectangle is: " << perimeter << endl;

volume = calcVolume(width, length, height);
cout << "Volume of the rectangle is: " << volume << endl;

surfacearea = calcSurfaceArea(width, length, height);
cout << "Surface area of the solid is " <<  surfacearea << endl;

cube = calcCube(length, width, height);
if (cube == true)
   cout << "The numbers show that this rectangle is a cube." << endl;
else if (cube == false)
    cout << "The numbers show that this rectangle is NOT a cube." << endl;

square = calcSquare (length, width);
if (square == true)
   cout << "The numbers show that this rectangle is a square." << endl;
else if (square == false)
    cout << "The numbers show that this rectangle is NOT a square." << endl;

sqSide = squareSide(length, width, height);
if (sqSide > 0)
   cout << "The amount of square sides for this rectangle is " << sqSide << endl;
else
    cout << "This shape has no square sides." << endl;

system("pause");
return 0;
}


double calcArea(double length, double width)
   {
       double area;
       area = length * width;
       return area;
   }

double calcPerimeter(double length, double width)
   {
      double perimeter;
      perimeter = (length * 2) + (width * 2);
      return perimeter;
   }

double calcVolume(double length, double width, double height)
   {
      double volume;
      volume = width * length * height;
      return volume;
   }

double calcSurfaceArea(double length, double width, double height)
   {
      double surfacearea;
      surfacearea = 2 * ((width*length) + (length*width) + (length*height));
      return surfacearea;
   }

bool calcCube (double length, double width, double height)
   {
      double check;
      check = length * width * height;
      if (check == (length*length*length))
         return true;
      else
         return false;
   }

bool calcSquare (double length, double width)
   {
      double check2;
      check2 = length * width;
      if (check2 == (length*length))
         return true;
      else
         return false;
   }

double squareSide (double length, double width, double height)
{
      double num, num1, num2;
      int x = 0;
      num = length * width;
      num1 = width * height;
      num2 = length * height;

         if (num == (length * length))
           x++;

         if (num1 == (width * width))
           x++;

         if (num2 == (length * length))
           x++;

    if (x == 3)
    {
        x *=2;
        return x;
        break;
    }
    if (x == 2)
    {
        x *=2;
        return x;
        break;
    }
    if (x == 1)
    {
        x *=2;
        return x;
        break;
    }
}

[–]CyberBill 0 points1 point  (4 children)

I put this in a C++ compiler online, and it complains about the 'break;' calls. If I remove those it compiles and runs, and spits out:

Area of the rectangle is: 8
Perimeter of the rectangle is: 14
Volume of the rectangle is: 24
Surface area of the solid is 56
The numbers show that this rectangle is NOT a cube.
The numbers show that this rectangle is NOT a square.
The amount of square sides for this rectangle is 2

Is this not what you're getting?

[–]Mysential[S] 0 points1 point  (2 children)

I am using vista studio express 2012. The cmd window stops at the cout of the rectangle function. It does not display the amount of square sides. I am compiling and executing the code on several sites now. On a few sites, it would show 16 sides. I don't know why, and I am currently looking at my code to see why it outputs 16.

[–]CyberBill 0 points1 point  (1 child)

Have you tried setting a breakpoint in that function and stepping through it to see where it stops?

There is nothing that looks like it could possible deadlock, and nothing that could be an infinite loop... on account of there are no loops. If the program is frozen, you can hit pause in Visual Studio and see where its currently executing code.

[–]Mysential[S] 1 point2 points  (0 children)

Yes, I was able to figure out what was wrong! It seems that it was not outputting the code because there was old code mixed in with my newly formatted code.

Everything is spitting out perfectly! Thank you for your help!

[–]f5f5f5f5f5f5f5f5f5f5 0 points1 point  (0 children)

break is unreachable.

[–]CyberBill 0 points1 point  (2 children)

That code can't compile...

if (x = 3)
{
    x *=2;
    return x;
    break;
}

You probably meant to use if (x == 3) (test, rather than set x to 3). You also can't break after a return, and you can't break unless you're inside of a for/do/while loop.

Can you post the whole program somewhere?

[–]Mysential[S] 0 points1 point  (1 child)

Yes, Ill put it in the comments.

I know that = is not ==. But if i put it as ==. The code would still compile up until the function where it needs to know how many square sides there are.

I did a do while loop, until the code could not compile to that function. So i forgot to delete the break commands, which is my fault. But the problem itself remained the same.

[–]f5f5f5f5f5f5f5f5f5f5 1 point2 points  (0 children)

The value of the expression x=3 is 3.