0

here is the snippet from in question from my code. a is for the array and c represents the counter. The code knows when i gained, lost, or stayed the same so it has the right value. Its just that it always displays 0 zero pounds as how much i lost or gained... is there something wrong with passing the %i in the printf with a[*c]-a[*c-1] ? I cant think of another way to subtract the difference

if(*c > 0){
    if(a[*c] > a[*c-1])
        printf("You gained gained %i pounds!\n",a[*c]-a[*c-1]);
    if(a[*c] < a[*c-1])
        printf( "You lost %i pounds!\n", a[*c-1] - a[*c]);
    if (a[*c] == a[back])
        printf("You're still the same weight as before..\n");
4

1 回答 1

1

printf 字符串中的整数标记是%d.

所以,试试这个:

 printf("You gained gained %d pounds!\n",a[*c]-a[*c-1]);
于 2013-11-02T23:21:32.787 回答