おつりの硬貨を計算してみましょう
・おつりを払い出す硬貨の種類ごとに変数を宣言します。
・計算するおつりの変数の宣言とおつりを設定します。
・おつりの枚数を順番に計算します。
・硬貨ごとにおつりの枚数を表示します。
//おつりの硬貨の枚数を計算するプログラム
//おつりを払い出す硬貨の種類ごとに変数を宣言する
dim yen500 //500円玉
dim yen100 //100円玉
dim yen50 //50円玉
dim yen10 //10円玉
dim yen5 //5円玉
dim yen1 //1円玉
//計算したいおつりの変数を宣言する
dim otsuri : otsuri = 877 //おつりを設定する
//おつりの枚数を計算する
//500円玉
yen500 = otsuri / 500
otsuri -= (yen500 * 500)
//100円玉
yen100 = otsuri / 100
otsuri -= (yen100 * 100)
//50円玉
yen50 = otsuri / 50
otsuri -= (yen50 * 50)
//10円玉
yen10 = otsuri / 10
otsuri -= (yen10 * 10)
//5円玉
yen5 = otsuri / 5
otsuri -= (yen5 * 5)
//1円玉
yen1 = otsuri
//おつりで払い出す硬貨の枚数を表示する
mes "500円玉"+str(yen500)+"枚"
mes "100円玉"+str(yen100)+"枚"
mes "50円玉"+str(yen50)+"枚"
mes "10円玉"+str(yen10)+"枚"
mes "5円玉"+str(yen5)+"枚"
mes "1円玉"+str(yen1)+"枚"
Copyright © 2002-2025 team.Dakuji All Rights Reserved.