I am a beginner to C (learning off free resources), I am trying to write a simple code to add a set of numbers inputted in by a user into a set of arrays....what am I doing wrong?
int numbers;
int number=1;
int counter = 0;
int pot[100];
int calculate;
int result;
printf("how many numbers do you want to calculate?:"); //asking user how many different integers would be calculated
scanf("%d",&numbers);
while (counter < numbers)
{
printf("input number %d\n", number);//asking user to input figures to be calculated
scanf("%d",&pot[0]+1); //user would input values into spaces in the array
counter++;
number++;
}
printf("Please press 1 for addition and 2 for multiplication");
scanf("%d",&calculate);
switch (calculate)
{
case 1: result = pot[0]+ pot[0]+1;//this is supposed to add all the individual values within the arrays
printf("the result is %d", result);
break;
case 2: result = pot[0]* pot[0]+1;//this is supposed to multiply all the individual values within the arrays
break;
}
return 0;
&pot[0]+1?numbersto be<100. (2) check return ofscanf:while(counter < numbers) { if(scanf("%d", &(pot[counter])) != 1) return 1; counter++; }, just to begin with. Please note that the variablecounteris your array's subscription index.