Hi, I've been having trouble in applying the void function in my simple program and wanting to avoid using the goto statement. My main goal is when the user inputs Y or y after a case in the switch function, I want loop back to the beginning of the program. So basically its a try again process that I wanna make simple. I'm not sure if I am using the right function declaration. Can any of you state my errors in the void function? Thanks.
START :
printf("Enter your desired operation: ");
scanf("%d", & op_1);
switch(op_1)
{
case 1 :
sum = num_1 + num_2;
cout<<"The sum of the two numbers is = "<<sum<<endl;
break;
case 2 :
diff = num_1 - num_2;
cout<<"The difference of the two numbers is= "<<diff<<endl;
break;
case 3 :
prod = num_1 * num_2;
cout<<"The product of the two numbers is = "<<prod<<endl;
break;
case 4 :
quo = num_1 / num_2;
cout<<"The quotient of the two numbers is = "<<quo<<endl;
break;
default : cout<<"Operation unknown!";
}
system("pause>0");
}
void displayCpp(int y_n)
{
cout<<"Do you want to try again(y/n)?: ";
cin>>y_n;
if (y_n == 'Y' || y_n == 'y')
{
system("cls");
goto START;
}
else if (y_n == 'N' || y_n == 'n')
{
system("pause>0");
}
}
Also, don't do this: pause("pause>0" . That little message from the pause statement is meant to be there. Piping the output message to null like that makes the application look like it's locking up.