Я создал это маленькое программное обеспечение, которое может рассчитывать поверхность и периметр прямоугольника и квадрата.Тем не менее, мне становится очень трудно запускать эту программу.Я имею в виду, что когда я пытаюсь запустить его, программное обеспечение прекрасно работает для «квадратной» части, но сразу закрывается, когда я перехожу к «прямоугольной» части.Может кто-нибудь мне помочь?Большое спасибо!
#include<iostream>
using namespace std;
int main ()
{
double a, b, c, answer, x, y, z;
cout << "Square (1) or rectangle (2) ";
cin >> x ;
if (x==1)
{
cout << "Square side: ";
cin >> a;
cout << " Type (2) if you would like to calculate the Perimeter or (1) if you would like to calculate the surface?";
cin >> y;
if (y == 1)
{
cout<<"The surface of the square is: ";
answer = ( a * a );
cout << answer << endl;
}
else if (y == 2)
{
cout << "The perimeter of the square is: ";
answer = (4*a);
cout << answer << endl;
}
else if (x==2)
{
cout << "The first side of the rectangle is: ";
cin >> c;
cout << "The second side of the rectangle is: ";
cin >> b;
cout << " Type (2) if you would like to calculate the Perimeter or (1) if you would like to calculate the surface? ";
cin >> z;
if (z == 1)
{
cout << "The surface of the rectangle is: ";
answer = (c*b);
cout << answer<<endl;
}
else if (z == 2)
{
cout << "The perimeter of the rectangle is: ";
answer = 2 * (c + b);
cout << answer << endl;
}
}
system("pause");
return 0;
}