> amount; 4 cout << endl; 5 int numBills1 = (int) (amount / 20.0); 6 if (numBills1 20.0< amount) { 7 numBills1++; 8} 9 cout << "How much will Jane be spending? "; 10 cin >> amount; 11 cout << endl; 12 int numBills2 = (int) (amount / 20.0); 13 if (numBills2 * 20.0 < amount) { 14 numBills2++; 15 } 16 cout << "John needs " << numBills1 << " bills" << endl; 17 cout << "Jane needs " << numBills2 << "bills" << endl; Function: Write a C++ function as described, not a complete program. ✔Submit
1. Define a function calculateBills that takes an amount as input:
1.1. Calculate the integer part of (amount / 20.0) and store it as numBills.
1.2. Check if (numBills * 20.0) is less than amount.
1.3. If the check is true, increment numBills by 1.
1.4. Return numBills.
2. Define a function spending that takes a personName as input:
2.1. Output a prompt to enter the spending amount for the person.
2.2. Read the spending amount from the user and store it in the amount variable.
2.3. Call the calculateBills function with the amount as input and store the result in numBills.
2.4. Output the person's name and the number of bills needed based on the calculated numBills.
3. In the main function:
3.1. Call the spending function for John with the name "John."
3.2. Call the spending function for Jane with the name "Jane."
4. End the program.
Step by step
Solved in 4 steps with 2 images