I can't access pastie.org from where I am now, but I think I can answer your questions.
> I'm using the goto function to always get me back to the beginning when
> the operation is complete or the user inputs something that he isn't
> supposed to input.
>
Conventional wisdom says that using goto is bad programming practice. In the hands of experts, a goto may not be bad. In general, it's a good idea not to use it. For this program, I'm sure you don't need a goto. A normal 'for', 'while', or 'do-while' loop will work.
> Works great with numbers but if the user inputs a letter, a infinite loop is started:
> Why is this happening?
>
You're probably using scanf.
> Is there a better way to do it?
> The program only does operations with two integers:
>
Yes. Use fgets and sscanf. E.g., to get two floats from the user, use a function like this:
void getFloat2(const char *p, float *a, float *b) {
bool inputOk;
printf("%s : ",p);
for (inputOk = false; inputOk == false; ) {
fgets(line,MAX_LINE_LEN,stdin);
inputOk = (sscanf(line,"%f ,%f%s",a,b,junk) == 2);
if (inputOk == false) {
printf("invalid input, try again: ");
}
}
}
If called this way:
getFloat2("Enter x,y",&coords[i].x,&coords[i].y);
The user can do this:
Enter x,y : 1.1,2.2
Enter x,y : 3 , 4
Enter x,y : 5.5, 6.6
I've defined 'line' and 'junk' to be arrays of char, with the size MAX_LINE_LEN. I've also declared bool:
typedef enum { false = 0, true } bool;
> What if i want to let the user chose the number of numbers:
> How do i tell the compiler to create variables for the numbers the user
> wants to add or whatever?
>
You can assume a maximum number of inputs, and declare an array that size. Or, have the user tell you how many numbers he wants to enter, and dynamically allocate an array, using malloc or calloc, to be filled with user input.
> What if the user wants to use floats?
> Can i convert a int to a float?
>
Yes. As you see above, you can scan for float, and if an int is entered it's ok.
> Why do i have to void main? I tried not voiding it and the results are the same.
>
You don't have to, and I don't think you should, declare main to be a function returning void. The standard declaration of main is this:
int main(int argc, char *argv[]);
> I should i use return 0?
>
Zero is a fine value to return.
> It's the same was not using it.
> So what does return do?
>
Returns a value to the caller. In the case of main, and especially with a console program you create, this return status is probably not used.