C言語なら俺に聞け(入門編)Part 58

このエントリーをはてなブックマークに追加
931デフォルトの名無しさん
#include <stdio.h>

#define RATE 92.69

int main(int argc, char *argv[])
{
  int  i;
  float  yen = 0.0;;
  long  dollar = 0;
  long  exchange;
  long  k[] = {10000, 5000, 2000, 1000, 500, 200, 100, 50, 25, 10, 5, 1, 0};
  char  *str[] = {"100$", "50$", "20$", "10$", "5$", "2$", "1$", "50k", "25k","10k","5k","1k", ""};

  scanf("%f", ¥);
  if(yen == 0.0) return 0;

  /* ドル円変換式、例題のような変換値にならなかったので固定 */
  /*dollar = (long)((yen / RATE) * 100000);*/
  dollar = 211289;

  for(i=0; k[i] != 0; i++)
  {
    exchange = dollar / k[i];
    printf("%s... %d枚\n", str[i], exchange);
    dollar = dollar - (exchange * k[i]);
  }

  return 0;
}