码迷,mamicode.com
首页 > 其他好文 > 详细

Ada 换硬币小程序

时间:2014-08-28 19:48:35      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:ada


with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;


procedure Main is

   type Coin is ( Penny, Nickel, Dime, Quarter, Half_Dollar, Dollar );
   
   Coin_Value : constant array ( Penny .. Dollar ) of Integer := 
     ( Penny => 1, 
       Nickel => 5,
       Dime => 10, 
       Quarter => 25, 
       Half_Dollar => 50, 
       Dollar => 100 );
   
   total_change,
   coin_count,
   num_dollars, 
   num_cents : Integer;
   
begin
   
   total_change := 0;
   
   Put_Line( "Enter the number of each coin : " );
   
   for next_coin in Penny .. Dollar loop
      Get( coin_count );
      total_change := total_change + coin_count * Coin_Value( next_coin );
   end loop;
   
   num_dollars := total_change / 100;
   num_cents := total_change rem 100;
   
   Put( "Total change is $" ); Put( num_dollars );
   if num_cents < 10 then
      Put( ".0" ); Put( num_cents );
   else
      Put( "." ); Put( num_cents );
   end if;
     
end Main;


Ada 换硬币小程序

标签:ada

原文地址:http://blog.csdn.net/pandora_madara/article/details/38902371

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!