undone98
undone98

Reputation: 77

array subscript is not an integer questions

hi i'm new to c and have never run into this error before and i'm a little confused as i dont believe i have declared any int's in my program at all however on likes 13, 14, 22, 23, 24, 35, and 40 i get array subscript is not an integer my code is as follows.

#include <stdio.h>

 int main(int argc, char const *argv[])
{
double mint[8];
double gum[8];
double count = 1.0,num,sum=0.0;

while(count <= 8)
{
    printf("please enter a number");
    scanf("%d",&num);
    mint[count]=num;
    printf("%d\n",mint[count] );
    count++;
}

count = 1;

while(count<=8)
{
    sum += mint[count];
    gum[count] = sum;
    printf("%d\n",gum[count] );
    count++;
}

count = 1.0;
sum = 1.0;

while(count<=8)
{
    while(sum<=8)
    {
        printf("%d",mint[sum] );
        sum++;
        if (sum==8)
            printf("\n");
    }
    printf("%d",gum[count] );
    count++;
}

return 0;
}   

Upvotes: 0

Views: 331

Answers (4)

Carl Norum
Carl Norum

Reputation: 225082

The error you're getting is referring to your use of double type to access an array:

mint[count]

Where count is a double.

Make count and sum be int to get rid of the warning.

As other answerers have noted - your program has several other problems as well. You might want to check out a beginner's tutorial someplace.

Upvotes: 0

Ed Heal
Ed Heal

Reputation: 60017

You have

double count = 1.0

then

mint[count]=num;

You cannot have indexes into an array that is a double - needs to be a integral number

Upvotes: 0

md5
md5

Reputation: 23717

You can't index an array with a double value. What if count is 2.4 for example?

Therefore you have to use an integer (int for instance).

Upvotes: 5

ouah
ouah

Reputation: 145899

scanf("%d",&num);

d expects a pointer to int not a pointer to double. Use lf if the argument is a pointer to double.

Same for printf:

printf("%d\n",mint[count] );

d expects an int not a double.

Upvotes: 3

Related Questions