Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Challenge: Simple Function Practice | Introduction to Functions
C++ Introduction (MS copy)
セクション 5.  4
single

single

book Challenge: Simple Function Practice

メニューを表示するにはスワイプしてください

Example of a Function with Arguments from the Previous Chapter

function.h

function.h

copy
123456
double 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 withdraw with a return type of int and two int parameters (balance and amount).
  • Use an if statement 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 (balance variable).

Example

withdraw(500, 200) => 300
withdraw(500, 500) => 0
withdraw(200, 500) => 200

解答

Switch to desktop実践的な練習のためにデスクトップに切り替える下記のオプションのいずれかを利用して、現在の場所から続行する
すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 5.  4
single

single

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

some-alt