単純なかけ算を利用したプログラムなんですが、エラーコードが出てきてしまって、全然デバックできません。
わかる方、どこがどういうふうに間違っているか、ご教授お願いします。
使っている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’
です。お願いします。
No.1ベストアンサー
- 回答日時:
scanfの二番目以降の引数には,変数のポインタを指定します.
単に変数名を書くとその変数の値を渡してしまうので,変数名の前に&記号を付ける必要があります.
具体的には,警告の出ている8行目,11行目を次のように直せばOKです.
scanf("%d,%d", &go, &hachi) ;
scanf("%d 円", &azukari) ;
参考URL:http://linuxjm.sourceforge.jp/html/LDP_man-pages …
早速のご返答ありがとうございます!
こんな単純なミスを犯すなんて、、、、ショックです。。
とても助かりました、ありがとうございます!
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
- ・ゆるやかでぃべーと タイムマシンを破壊すべきか。
- ・歩いた自慢大会
- ・許せない心理テスト
- ・字面がカッコいい英単語
- ・これ何て呼びますか Part2
- ・人生で一番思い出に残ってる靴
- ・ゆるやかでぃべーと すべての高校生はアルバイトをするべきだ。
- ・初めて自分の家と他人の家が違う、と意識した時
- ・単二電池
- ・チョコミントアイス
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
「指定されたキャストは有効で...
-
C言語 エラーの原因がわからな...
-
C言語での引数の省略方法
-
【C++】関数ポインタの使い方
-
C言語での奇数の和
-
#define _CRT_SECURE_NO_WARNIN...
-
int型の変数値をバイト列として...
-
CStringの配列要素を関数で受け...
-
C++でvectorにテキストファイル...
-
実数の整数部,小数部の取得
-
PowerShellがうまくいかない
-
「{ } で囲むだけ」は正しい?
-
system関数がうまくいかない
-
ColorをRGBで指定する方法
-
エラー 添字が付けられた値が、...
-
C言語で分からないところがあり...
-
入力を待たずにstdinの監視をし...
-
ラップ関数とはどんなものですか?
-
Arduinoのプログラムにエラーが...
-
【至急】プログラムにエラーが...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
「指定されたキャストは有効で...
-
C言語での引数の省略方法
-
#define _CRT_SECURE_NO_WARNIN...
-
AtCoderABC135の問題Cについて
-
C言語 エラーの原因がわからな...
-
複数桁10進数の*桁目だけを抽出...
-
【C++】関数ポインタの使い方
-
実数の整数部,小数部の取得
-
ラップ関数とはどんなものですか?
-
if と配列の組み合わせ
-
return 1L
-
read関数をノンブロッキングで...
-
(int *)の意味
-
std::set<int> で、ある値が何...
-
Win32APIで作るコンボボックス...
-
C++でvectorにテキストファイル...
-
「{ } で囲むだけ」は正しい?
-
足して100になるような乱数のア...
-
Arduinoのプログラムにエラーが...
-
課題でつまってます・・・
おすすめ情報