> 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

icon
Related questions
Question
<percentageGrade
You are working on problem set: PS4 (Pause)
Pause) i
→ spending ♡
Language/Type:
Related Links:
C++if/else input redundancy console input
string
Main Page → Exercises → PS4→ C++ → Solve an Exercise
The following code is poorly structured. Rewrite it so that it has a better structure and avoids redundancy. To help
eliminate redundancy, convert the code into a function named spending that accepts as its parameter a string for
a single person's name, and prints the appropriate information about that person's bills. Your function could be
called twice (once for John and once for Jane) to replicate the original code's behavior.
1 cout << "How much will John be spending? ";
2 double amount;
3 cin >> 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
Transcribed Image Text:<percentageGrade You are working on problem set: PS4 (Pause) Pause) i → spending ♡ Language/Type: Related Links: C++if/else input redundancy console input string Main Page → Exercises → PS4→ C++ → Solve an Exercise The following code is poorly structured. Rewrite it so that it has a better structure and avoids redundancy. To help eliminate redundancy, convert the code into a function named spending that accepts as its parameter a string for a single person's name, and prints the appropriate information about that person's bills. Your function could be called twice (once for John and once for Jane) to replicate the original code's behavior. 1 cout << "How much will John be spending? "; 2 double amount; 3 cin >> 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
<percentageGrade
You are working on problem set: PS4 (Pause)
Pause) i
→ spending ♡
Language/Type:
Related Links:
C++if/else input redundancy console input
string
Main Page → Exercises → PS4→ C++ → Solve an Exercise
The following code is poorly structured. Rewrite it so that it has a better structure and avoids redundancy. To help
eliminate redundancy, convert the code into a function named spending that accepts as its parameter a string for
a single person's name, and prints the appropriate information about that person's bills. Your function could be
called twice (once for John and once for Jane) to replicate the original code's behavior.
1 cout << "How much will John be spending? ";
2 double amount;
3 cin >> 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
Transcribed Image Text:<percentageGrade You are working on problem set: PS4 (Pause) Pause) i → spending ♡ Language/Type: Related Links: C++if/else input redundancy console input string Main Page → Exercises → PS4→ C++ → Solve an Exercise The following code is poorly structured. Rewrite it so that it has a better structure and avoids redundancy. To help eliminate redundancy, convert the code into a function named spending that accepts as its parameter a string for a single person's name, and prints the appropriate information about that person's bills. Your function could be called twice (once for John and once for Jane) to replicate the original code's behavior. 1 cout << "How much will John be spending? "; 2 double amount; 3 cin >> 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
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer