我想要做一個程式
販賣機 幣值有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.