I'm learning C, and am currently working my way up through command-line programs. I'm interested in writing a program which would add n terms to eachother, much like would a normal calculator. The number n would be defined by the number of terms the user enters (as opposed to a user-specified n inputted explicitly by the user before the operation). How can this be done? Should I use a while
loop for this?
So far, I've tried simply defining a finite number of terms a user can enter (up to 10 terms, if it's fewer, simply replace the remaining terms with zeros).
scanf("%f%c%f%cf%cf%cf%cf%cf%cf%cf%cf", &num1, &op, &num2, &op, &num3, &op, &num4, &op, &num5, &op, &num6, &op, &num7, &op, &num8, &op, &num9, &op, &num10);
// addition
if (strcmp(&menuchoice, "a") == 0)
{
num3 = num1+num2+num3+num4+num5+num6+num7+num8+num9+num10;
return num3;
}