This seems like a fair enough use of goto, personally. The effect of the goto is clear, it won't involve any magic to modify the program without changing the effect of the goto, and I mean, it's just one goto in the program.
It all really just depends on how you are modelling your program. If you're thinking of your program as a state machine (ie, flowchart), then break; continue; and goto X; are most certainly your friends. State machines are intuitive and good for expressing algorithms that aren't too large.
Personally, I'm skeptical about the use of flags to handle program flow like this, and suggest that if you're not going to use goto, use smaller functions that return a value indicating whether the function completed succesfully, and flow your program based on those returns.
Here is a modularized pseudocode version of your code, which handles a bad input for X
Code:
#include <stdio.h>
int main()
#define N 15
{
int i, sets;
float x[N], y[N], area;
char again='Y';
while(again=='y'||again=='Y')
{
area=0;
printf("This is a program to integrate using the trapezium rule\n");
printf("Enter the number of coordinate sets you wish to use, up to %d\n\n", N);
if (getNumSets() == SUCCESS)
{
if (getX() == SUCCESS);
{
getY();
doMath();
}
}
else printf("\nYou have entered an invalid integer\n\n");
printf("Would you like to run the program again?\n");
printf("Type Y or y for yes, anything else for no\n");
again=getchar();
if(again=='\n')again=getchar();
}
return 0;
}
If you want to implement that design without splitting your code into functions, it will have to look something like this (this is the method using flags)...
Code:
#include <stdio.h>
int main()
#define N 15
{
int i, sets;
float x[N], y[N], area;
char again='Y';
int xFlag; // <-- I added this
while(again=='y'||again=='Y')
{
// Blah blah....
xFlag = 1; // <-- added
for(i=0; i<=sets-1; i++)
{
scanf("%f", &x[i]);
if(x[i] < x[i-1])
{
printf("The value you entered is less than the previous\n\n");
xFlag = 0; // <-- added
break;
}
}
// The flag is now 0 if there was a problem, and 1 if there wasn't
if(xFlag != 0) <-- added
{ <-- added
printf("Type in %d values for the y coordinates\n", sets);
// Blah Blah...
printf("area is %f\n\n", area);
} // end if (xFlag) // <-- added
}
else printf("\nYou have entered an invalid integer\n\n");
printf("Would you like to run the program again?\n");
printf("Type Y or y for yes, anything else for no\n");
again=getchar();
if(again=='\n')again=getchar();
}
return 0;
}