What is the output of the following code snippet? int main() { int num_deposits
ID: 3929225 • Letter: W
Question
What is the output of the following code snippet?
int main()
{
int num_deposits = 1;
double balance = 30;
double initial_balance = 50;
double deposit = 10.0;
while (balance <= initial_balance)
{
balance = balance + deposit;
num_deposits++;
}
cout << "Deposits: " << num_deposits << " Balance: ";
cout << balance << endl;
return 0;
}
Deposits: 3 Balance: 50
Deposits: 3 Balance: 60
Deposits: 4 Balance: 50
Deposits: 4 Balance: 60
1)Deposits: 3 Balance: 50
2)Deposits: 3 Balance: 60
3)Deposits: 4 Balance: 50
4)Deposits: 4 Balance: 60
Explanation / Answer
num_deposits = 1
balance = 30
initial_balance = 50
deposit = 10
30<=50 : True
balance = 30+10 = 40
num_deposit = 1+1 = 2
40<=50 : True
balance = 40+10 = 50
num_deposit = 2+1 = 3
50<=50 : True
balance = 50+10 = 60
num_deposit = 3+1 = 4
hence the output is :
Deposits: 4 Balance: 60
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.