1 Replies - 480 Views - Last Post: 21 September 2015 - 02:40 PM Rate Topic: -----

#1 soundestmammal   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-September 15

Having some trouble with program (BASIC Variables)

Posted 21 September 2015 - 01:37 PM

#include <stdio.h>


int main() {
    int distance, time, speed ;
    printf("Enter the number of furlongs traveled : ");
    scanf("%d" , &distance);
    printf("Enter the number of fortnights it took : ");
    scanf("%d" , &time);

    speed = distance / time ;

    printf("Your speed is '%d' furlongs-per-fortnight", &speed);
   return 0;
}


I keep getting an error warning in my code as follows...

speed.c:13:57: warning: format specifies type 'int' but the argument has type
'int *' [-Wformat]
printf("Your speed is '%d' furlongs-per-fortnight", &speed);
~~ ^~~~~~
1 warning generated.

This post has been edited by Salem_c: 21 September 2015 - 01:40 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Having some trouble with program (BASIC Variables)

#2 Xupicor   User is offline

  • Nasal Demon
  • member icon

Reputation: 457
  • View blog
  • Posts: 1,179
  • Joined: 31-May 11

Re: Having some trouble with program (BASIC Variables)

Posted 21 September 2015 - 02:40 PM

format specifies type 'int' but the argument has type
'int *'

That says it all, really. The %d specifies that an argument of type int should be passed, but you passed &speed - an address of speed, in other words - int* instead of int.

This post has been edited by Xupicor: 21 September 2015 - 02:41 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1