【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?

単純なかけ算を利用したプログラムなんですが、エラーコードが出てきてしまって、全然デバックできません。
わかる方、どこがどういうふうに間違っているか、ご教授お願いします。
使っているPCはMacBook Proです。

#include <stdio.h>

int main( void )
{
int go, hachi, goukei, azukari, otsuri ;

printf("五十円切手の枚数と八十円切手の枚数を入力してください。(例 10,4):") ;
scanf("%d,%d", go, hachi) ;
goukei = go * 50 + hachi * 80 ;
printf("合計金額は%dです、いくら支払いますか?:",goukei) ;
scanf("%d 円",azukari) ;
otsuri = azukari - goukei ;
printf("ありがとうございました、おつりは %d 円です。",otsuri) ;
return 0 ;
}

エラー内容
q2_5.c: In function ‘main’:
q2_5.c:8: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int’
q2_5.c:8: warning: format ‘%d’ expects type ‘int *’, but argument 3 has type ‘int’
q2_5.c:8: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int’
q2_5.c:8: warning: format ‘%d’ expects type ‘int *’, but argument 3 has type ‘int’
q2_5.c:11: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int’
q2_5.c:11: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int’

です。お願いします。

A 回答 (1件)

scanfの二番目以降の引数には,変数のポインタを指定します.


単に変数名を書くとその変数の値を渡してしまうので,変数名の前に&記号を付ける必要があります.

具体的には,警告の出ている8行目,11行目を次のように直せばOKです.

scanf("%d,%d", &go, &hachi) ;
scanf("%d 円", &azukari) ;

参考URL:http://linuxjm.sourceforge.jp/html/LDP_man-pages …
    • good
    • 0
この回答へのお礼

早速のご返答ありがとうございます!
こんな単純なミスを犯すなんて、、、、ショックです。。
とても助かりました、ありがとうございます!

お礼日時:2012/09/25 21:16

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!


おすすめ情報