I've been working on a console based calculator app, and I wanted to use 2 functions in order to make it look cleaner (I didn't want main having too many lines), so I decided to use goto to jump from main to my foil function, then another goto to jump back to the start of main. I was just wondering if it's unsafe to do this. Thanks :)
void foileq()
{
int a, b, c, d;
printf("Enter the 4 numbers\n");
cin >> a;
cin >> b;
cin >> c;
cin >> d;
cout << a * c << " " << a * d << " " << b * c << " " << b * d << endl;
}
int main()
{
float a, b;
string type = "";
BEGIN:
{
while (1)
{
printf("Add,subtract,multiply,divide,foil,power?\n");
cin >> type;
if (type == "foil")
{
goto FOIL;
continue;
}
else
{
printf("Enter A number\n");
cin >> a;
printf("Enter another number\n");
cin >> b;
if (strcmp(type.c_str(), "add") == 0)
printf("%.2f\n", a + b);
else if (strcmp(type.c_str(), "subtract") == 0)
printf("%.2f\n", a - b);
else if (strcmp(type.c_str(), "multiply") == 0)
printf("%.2f\n", a * b);
else if (strcmp(type.c_str(), "divide") == 0)
printf("%.2f\n", a / b);
else if (strcmp(type.c_str(), "power") == 0)
printf("%.2f\n", pow(a, b));
}
}
}
FOIL:
foileq();
goto BEGIN;
}