close
Blogtrottr
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 發問中
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 發問中 
C程式做販賣機問題
Nov 17th 2014, 15:33

我想要做一個程式
販賣機 幣值有50 10 5 1 元

然後輸入硬幣後^Z 可以得知有什麼商品可選擇
例如
輸入10元
可以買紅茶 綠茶
輸入18元(10 5 1 1 1)
可以買可樂
輸入50元
可以買5罐紅茶 綠茶 或兩罐可樂

以下是我的程式
#include

/* function main begins program execution */
int main( void )
{
int coin=0;
int Count_50 = 0; /* number of 50s */
int Count_10 = 0; /* number of 10s */
int Count_5 = 0; /* number of 5s */
int Count_1 = 0; /* number of 1s */
int t;
int total;

printf( "歡迎光臨販賣機\n" );
printf( "請投入金額\n" );

while ( (t = scanf("%d", &coin)) >0 ) {

/* determine which grade was input */
switch ( coin ) { /* switch nested in while */

case 50:
++Count_50;
if( coinbreak;
}
case 10:
++Count_10;
if( coinbreak;
}
case 5:
++Count_5;
if( coinbreak; /* exit switch */
}
case 1:
++Count_1;
if( coinbreak;
}
default:
printf( "輸入錯誤" );
printf( "請重新輸入\n" );
break; /* optional; will exit switch anyway */
} /* end switch */
} /* end while */

total=Count_50*50+Count_10*10+Count_5*5+Count_1*1;
printf("總共有%d元\n",total);

return 0;
}

請問必需怎麼改呢 謝謝

This entry passed through the Full-Text RSS service - if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers.

You are receiving this email because you subscribed to this feed at blogtrottr.com.

If you no longer wish to receive these emails, you can unsubscribe from this feed, or manage all your subscriptions
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 nbv2x14xp1p6k 的頭像
    nbv2x14xp1p6k

    線上遊戲排行榜2013/2014,進擊的巨人線上看,candy crush saga外掛,正妹寫真三圍

    nbv2x14xp1p6k 發表在 痞客邦 留言(0) 人氣()