Okay new submission for my last question. I was a little mixed up before. Honestly I kinda still am.
If the user puts in a 6. I need the array to display the even number from 0 - 6.
Right now what it does is it displays the first six even numbers.
Okay as I'm writing this I'm starting to see where my problem might be..
Code:
void sumIntegers ()
{
int arr[50];
int i = 0;
int num = 0;
int sum = 0;
printf("\nI want to sum up even integers <= 50.\n\n");
do
{
printf("\nPlease enter a positive integer:\n\n\t\t\t");
scanf(" %d", &num);
if(num < 0)
printf("\n*** Negative numbers are invalid! ***\n\n\n");
for (i = 1; i < num; i++)
{
arr[i] = 2 * i;
}
for (i = 1; i < num; i += 1)
{
printf("%d\n", arr[i]);
}
for(i = 1; i < num; i++)
{
if (arr[i] % 2 == 0)
sum += arr[i];
}
}
while(num <= 0);
printf("\n\nThe sum of the even numbers from 0 to %d = %d\n\n\n", num, sum);
return;
}