I'm a teenager trying to learn C++. I used to use Batch because all I wanted to program at that time was simple CYOA games. In batch, there's a system that divides codes like so:
@echo off
[Pretend there's some elaborate code here]
...
:menu
echo Would you like to go again?
echo 1. Yes
echo 2. No
set /P choice1="Choice: "
set choice=
if '%choice%'=='1' goto :menu
if '%choice%'=='2' exit
and then 'goto :menu' would take you back to the start of that section and redo the code again. I'm aware of loops, but is there a function that works just like this? If it helps, here's my (very simple) code.
#include <iostream>
using namespace std;
int main()
{
int num1;
int num2;
int product;
int sum;
string response;
cout << "Enter two numbers separated by commas.\n";
cin >> num1, num2;
product = num1 * num2;
sum = num1 + num2;
if (product>sum){
cout << "The product is larger than the sum.";
}
else{
cout << "The sum is larger than the product.";
}
cout << "Would you like to do this again? Y/N\n";
cin >> response
if (response==Y)
return 0;
}