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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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.

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
Transcribed Image Text: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
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
↑
↑
Transcribed Image Text: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 ↑ ↑
Expert Solution
Step 1: Introduction

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.

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Binary numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education