QUESTION IMAGE
Question
challenge activity 3.10.2: soda machine with enums. the following program reads a number from input to indicate the coin inserted into a soda machine. organize the lines of code to add 10 to totaldeposit if the input is a dime. otherwise, if the input is a nickel, add 5 to totaldeposit. ex if the input is 1, representing named value add_dime, then the output is: totaldeposit: 10 note: not all lines of code on the left will be used in the final solution. how to use this tool unused totaldeposit = totaldeposit + 10; totaldeposit + 10; else if (userinput == add_dime) { else { totaldeposit = totaldeposit + 5; totaldeposit + 5; } else if (userinput == add_nickel) { } main.cpp #include <iostream> using namespace std; int main() { enum acceptedcoins {add_quarter, add_dime, add_nickel}; int totaldeposit; int userinput; totaldeposit = 0; cin >> userinput; if (userinput == add_quarter) { totaldeposit = totaldeposit + 25; } else { cout << \invalid coin selection.\ << endl; } load default template...
Step1: Insert DIME condition block
else if (userInput == ADD_DIME) {
totalDeposit = totalDeposit + 10;
}
Step2: Insert NICKEL condition block
else if (userInput == ADD_NICKEL) {
totalDeposit = totalDeposit + 5;
}
Step3: Add output for totalDeposit
cout << "totalDeposit: " << totalDeposit << endl;Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
The completed main.cpp code is:
#include <iostream>
using namespace std;
int main() {
enum AcceptedCoins {ADD_QUARTER, ADD_DIME, ADD_NICKEL};
int totalDeposit;
int userInput;
totalDeposit = 0;
cin >> userInput;
if (userInput == ADD_QUARTER) {
totalDeposit = totalDeposit + 25;
}
else if (userInput == ADD_DIME) {
totalDeposit = totalDeposit + 10;
}
else if (userInput == ADD_NICKEL) {
totalDeposit = totalDeposit + 5;
}
else {
cout << "Invalid coin selection." << endl;
}
cout << "totalDeposit: " << totalDeposit << endl;
return 0;
}
When input is 1 (ADD_DIME), output is:totalDeposit: 10
When input is 2 (ADD_NICKEL), output is:totalDeposit: 5
When input is 0 (ADD_QUARTER), output is:totalDeposit: 25
When input is invalid, output is:Invalid coin selection.totalDeposit: 0