首页 > 代码库 > Ada 换硬币小程序
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 换硬币小程序
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。