セクション 5. 章 4
single
Challenge: Simple Function Practice
メニューを表示するにはスワイプしてください
Example of a Function with Arguments from the Previous Chapter
function.h
123456double convert_usd_to_eur(double usd_amount) { const double exchange_rate = 0.91; double euros = usd_amount * exchange_rate; return euros; }
タスク
スワイプしてコーディングを開始
Create a function withdraw that simulates a bank account withdrawal. It accepts the current balance and withdrawal amount as arguments. If the balance is sufficient, deduct the amount and return the new balance. Otherwise, return the original balance.
- Implement a function
withdrawwith a return type ofintand twointparameters (balanceandamount). - Use an
ifstatement to check if the balance is sufficient for the withdrawal. - If the balance is sufficient, return the new balance after subtracting
amount. - If the balance is insufficient, return the original balance (
balancevariable).
Example
withdraw(500, 200) => 300
withdraw(500, 500) => 0
withdraw(200, 500) => 200
解答
すべて明確でしたか?
フィードバックありがとうございます!
セクション 5. 章 4
single
AIに質問する
AIに質問する
何でも質問するか、提案された質問の1つを試してチャットを始めてください