0

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;
}   
1
  • 2
    i dont believe i have declared any int's in my program Yeah, exactly. That's what the error is moaning about. Commented Feb 7, 2013 at 19:34

4 Answers 4

5

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).

Sign up to request clarification or add additional context in comments.

Comments

3
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.

1 Comment

That's not the OP's problem. I mean, it is a problem. But not the one he's asking about.
0

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

Comments

0

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.

1 Comment

Or, preferably, a peer-reviewed book. Poor coding like this comes from reading "beginner's tutorials" that you found "someplace".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.