[ create a new paste ] login | about

Link: http://codepad.org/Nhl8WS7Q    [ raw code | output | fork ]

C, pasted on Jul 7:
/* Q.2ディスカウントストアでどの商品でも5個以上買えば1割引、10個以上で2割引、20個以上で */
/* 4割引となっていた。キーボードから買う商品の単価と個数を入力し、合計金額を計算するプログラミングを */
/* 作成せよ。 */

#include <stdio.h>

int main()
{
  int unit_price; // 単価
  int num; // 個数

  printf( "買う商品の単価: " );
  scanf( "%d", &unit_price );

  printf( "個数: " );
  scanf( "%d", &num );

  int total_price = unit_price * num;

  // 小数を使うと誤差がでるので使わない
  if ( num >= 20 )
    total_price = total_price*6/10;
  else if ( num >= 10 )
    total_price = total_price*8/10;
  else if ( num >= 5 )
    total_price = total_price*9/10;

  printf( "合計金額: %d", total_price );
}


Output:
1
2
買う商品の単価: 個数: 合計金額: -1868205976
Exited: ExitFailure 25


Create a new paste based on this one


Comments: