What change do i make to fix my code so it will not output negative numbers for the future years. Here is the code. and output. HOW CAN I FIX THE ARITHMETIC OVERFLOW? and here is the question. If P is the population of the first day of the year, B is the birth rate and D is the death rate, the estimated population at the end of the next year is given by formula: P + ( B * P ) / 100 – ( D * P ) / 100 The population growth rate is given by the formula: B - D Write a program that prompts the user to enter the starting population, birth and death rates and the number of years to project. The program should then calculate and print the growth rate and the estimated population after each year. Your program must contain the following functions: GrowthRate: This function takes as its parameters the birth and death rates and returns the population growth rate. Estimated Population: This function takes as its parameters the current population, the birth rate and the death rate. It returns the estimated population for the next year. Your program should not accept negative birth rate, negative death rate or population of less than 2.
What change do i make to fix my code so it will not output negative numbers for the future years. Here is the code. and output. HOW CAN I FIX THE ARITHMETIC OVERFLOW?
and here is the question.
If P is the population of the first day of the year, B is the birth rate and D is the death rate, the estimated population at the end of the next year is given by formula:
P + ( B * P ) / 100 – ( D * P ) / 100
The population growth rate is given by the formula: B - D
Write a
GrowthRate: This function takes as its parameters the birth and death rates and returns the population growth rate.
Estimated Population: This function takes as its parameters the current population, the birth rate and the death rate. It returns the estimated population for the next year. Your program should not accept negative birth rate, negative death rate or population of less than 2.
![X
✓ Filter
Ex
U
A Homework 1
2:3
Homework 1)
2 // main.cpp
3 // Homework 1
4
5
6
7
8 #include <iostream>
F8D2N2≈±±✿~✿IG FINNHAN
9
10 using namespace std;
11
17
19
12 float growthRate(int birth_Rate, int death_Rate) {
13
return birth_Rate - death_Rate;
14 }
15
16
18 }
23
20 int main()
21 {
24
25
26
27
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
C* main
//
// Created by Nicholas Florio on 9/11/23.
//
56
57 }
Homework 1 C* main
float est Population (int birth_Rate, int population, int death_Rate) {
return population + (birth_Rate * population) / 100 - (death_Rate * population) / 100;
Homework 1 My Mac
float birth_Rate;
float population;
float death_Rate;
int num_Years;
f main()
cout << "Enter the Birth Rate << endl;
cin >> birth_Rate;
cout << "Enter the Population " << endl;
cin >> population;
}
cout << "Enter the Death Rate << endl;
cin >> death_Rate;
cout << "Enter the number of years to project: ";
cin >> num_Years;
}
// Check for invalid inputs
if (population < 2 || birth_Rate < 0 || death_Rate < 0) {
cout << "Invalid input. Population must be >= 2, and birth and death rates must be non-negative." << endl;
return 1;
// Calculate and display the population growth rate
double growth = growthRate (birth_Rate, death_Rate);
cout << "Population growth rate: " << growth << "% per year" << endl;
// Calculate and display estimated population for each year
for (int year = 1; year <= num_Years; year++) {
return 0;
Finished running Homework 1
population = est Population (population, birth_Rate, death_Rate);
cout << "Estimated population after year. << year << ": " << (int) (population) << endl;
||
I
P
WH
20
Line: 24 Col: 22
+
6
2.
No Selection
H](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fa04ce243-abd6-4ae0-aef9-d7b4f06e1af0%2F06c0c510-1a3b-41fc-a7be-228050893831%2Flitzs4b_processed.png&w=3840&q=75)
![X
✓ Filter
Ex
U
A Homework 1
2:3
Homework 1)
C* main
20
1
2
3
4 //
5
// Created by Nicholas Florio on 9/11/23.
6
//
7
8
9
10
11
Auto
//
main.cpp
// Homework 1
Homework 1 c* main
#include <iostream>
17
18 }
19
20 int main()
21
{
22
23
24
25
26
27
28
using namespace std;
float growthRate (int
return birth_Rate
O
Homework 1 My Mac
12
13
14 }
15
16 float est Population (int birth_Rate, int population, int death_Rate) {
return population + (birth_Rate * population) / 100 (death_Rate * population) / 100;
float birth_Rate;
float population;
float death_Rate;
int num_Years;
f main()
birth_Rate, int death_Rate) {
death_Rate;
cout << "Enter the Birth Rate " << endl;
cin >> birth_Rate;
Filter
Finished running Homework 1
-
All Output
Enter the Birth Rate
75645
Enter the Population
574664
Enter the Death Rate
5764
Enter the number of years to project: 8
Population growth rate: 69881% per year
Estimated population after year 1: 923321
Estimated population after year 2: 6966871
Estimated population after year 3: -17004738
Estimated population after year 4: -25566376
Estimated population after year 5: -16616825
Estimated population after year 6: 10172374
Estimated population after year 7: 2616320
Estimated population after year 8: -854225
Program ended with exit code: 0
→ Filter
P
G
▬▬▬▬▬▬▬▬▬▬▬▬▬ – 1
E0
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 1.
Line: 24 Col: 22
EP
+
+
U
Identity and Type
Name main.cpp
Type Default - C++ Source
Relative to Group
main.cpp
Location
Full Path /Users/nick/Desktop/
Homework 1/Homework 1/
main.cpp
On Demand Resource Tags
Only resources are taggable
Target Membership
Homework 1
Text Settings
Text Encoding No Explicit Encoding
Line Endings No Explicit Line Endings
Indent Using Spaces
Widths
4
Tab
Wrap lines
Indent
A
4
C
↑
↑](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fa04ce243-abd6-4ae0-aef9-d7b4f06e1af0%2F06c0c510-1a3b-41fc-a7be-228050893831%2Fdo1885p_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
The program below provides a simulation to find the estimated population after a certain number of years, given the starting population, birth rate, and death rate. It first takes user input for the starting population, birth rate, death rate, and number of years to project. It then calculates and prints the population growth rate and the estimated population after each year for the projected number of years.
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)