No, you should
eliminate all of the goto's, not just reduce them.
Secondly, a program riddled with goto's are not "simple". It's simple because you put them in, but most programmers who look at your code will not put any effort into understanding it if it has goto's in it.
Look at this example (not compiled):
Code:
#include <iostream>
char getResponse()
{
char answer;
bool inputOK = false;
do
{
std::cout<<"Do you wish to continue: Y/N ";
std::cin>>answer;
switch (answer)
{
case 'y':
case 'Y':
case 'n':
case 'N':
inputOK = true;
break;
default:
std::cout<<"Invalid characters. Use Y/N or y/n.\n\n";
}
} while ( !inputOK );
return answer;
}
int add()
{
char answer;
int a,b;
int total;
do
{
std::cout<<"Enter first number: ";
std::cin>>a;
std::cout<<"Enter Second number: ";
std::cin>>b;
total = a+b;
std::cout<<"\nSum: "<< total <<"\n\n";
answer = getResponse();
} while (answer == 'Y' || answer == 'y');
std::cout<<"Returning to menu";
return 0;
}
Just add a function to get the response. Then the code doesn't turn into spaghetti using goto's.
http://en.wikipedia.org/wiki/Spaghetti_code
Regards,
Paul McKenzie