If I use classes, will this reduce my lines of code?
Is this a good way?
Should I use a header for certain functions?
Thanks
(

Just wondering, thanks

/* Ask how many sides a shape has, 
go to that shape, 
ask for values to do questions about the shape
give answers
repeat
*/

#include <cstdlib>
#include <iostream>

using namespace std;
int Perimeter(int x, int y);
int Area(int x, int y);
int ChangeSize();

void SquaresAndRectangles();

int length, width, option;
bool program = true; 

int main(int argc, char *argv[])
{
    int sides;
    do
    {
    
    
    cout << "How many sides does your shape have?\t";
    
    cin >> sides;
    switch(sides)
    {
                 case 4:
                        cout << "Your shape is a square or a rectangle.\n";
                        SquaresAndRectangles();
                        break;
                 case 3:
                        cout << "Your shape is a triangle.\n";
                       
                        break;
                 default:
                         cout << "This is geometry, be realistic\n";
    }
}while ( sides != 4 || 3);
    

    cin.get();
    return EXIT_SUCCESS;
}

void SquaresAndRectangles()
{
    cout << "Please enter the length of your shape\t";
    cin >> length;
    cout << "Please enter the width of your shape\t";
    cin >> width;
    while ( program = true )
    {
    cout << "(1):\tArea\n(2):\tPerimenter\n(3):\tChange Sizes";
    cin >> option;
    switch(option)
                  {
                  case 1:
                         Area(length, width);
                         break;
                  case 2:
                         Perimeter(length, width);
                         break;
                  case 3:
                         ChangeSize();
                  
                  default:
                         break;
                  }
    }  
} 

int Perimeter(int x, int y)
{
    int Perimeter = x*2 + y*2;
    cout << "The perimeter of your shape is " << Perimeter << ".\n";
    return Perimeter;
};
int Area(int x, int y)
{
  int Area = x*y;
  cout << "The area of your shape is " << Area << ".\n";
  return Area;  
};

int ChangeSize()
{
    cout << "Please enter the length of your shape\t";
    cin >> length;
    cout << "Please enter the width of your shape\t";
    cin >> width;
    return length;
    return width;
     }

Recommended Answers

All 4 Replies

Please go to C forum. The code you presented is not in Java.

This is the c++ forum....Your in the wrong forum, lol

Does this program run correctly? Lines 57-75 looks like it is an infinite loop. On lines 97 and 98 you have 2 return statements. You can only return one thing from a function. This is not to say you cant have a multiple returns in a function, you just cant have it like you have it.

int foo()
{
    int bar = 5;
    int temp = 6;
    return bar;
    return temp;  // this is incorrect.
}

int foo()
{
    int bar = 5;
    int temp = 8;
    if (bar > temp)
        return temp;
    return bar; // this is fine since the first return is in a conditional
}

thanks for that tidbit, the code runs fine, I dont even think I need the returns, ive added a lot more stuff too

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.