Question

In: Computer Science

Write a C++ program that inputs the world's population at the end of last year. Assume...

Write a C++ program that inputs the world's population at the end of last year. Assume population is growing at a rate of 1.12%.

Output the year (starting with this year) and the population until the population is greater than 10billion.

Test data: 6.83 billion. (leave like this rather than 6800000000).

Name as a comment and printed to output. Output as a comment at the bottom of the code

Solutions

Expert Solution

#include <iostream>

using namespace std;

int main()
{
double p,rate=1.12,total=0;
int y;
  
cout << "Enter worlds population in billion" << endl;
cin>>p;
cout << "Enter the year" << endl;
cin>>y;
while(total<10) // to check total population is less than 10 billion.
{
total=p+((1.12*p)/100);
p=total;
cout<<"year:"<<++y<< endl;
cout<<"Total population"<< p<<"billion"<< endl;
}

return 0;
}

---------------------------------------------output----------------------------------------------------------------------------

Enter worlds population in billion

6.83
Enter the year

2011

year:2012
Total population :6.9065billion
year:2013
Total population :6.98385billion
year:2014
Total population :7.06207billion
year:2015
Total population :7.14116billion
year:2016
Total population :7.22114billion
year:2017
Total population :7.30202billion
year:2018
Total population :7.3838billion
year:2019
Total population :7.4665billion
year:2020
Total population :7.55013billion
year:2021
Total population :7.63469billion
year:2022
Total population :7.7202billion
year:2023
Total population :7.80666billion
year:2024
Total population :7.8941billion
year:2025
Total population :7.98251billion
year:2026
Total population :8.07192billion
year:2027
Total population :8.16232billion
year:2028
Total population :8.25374billion
year:2029
Total population :8.34618billion
year:2030
Total population :8.43966billion
year:2031
Total population :8.53418billion
year:2032
Total population :8.62977billion
year:2033
Total population :8.72642billion
year:2034
Total population :8.82415billion
year:2035
Total population :8.92299billion
year:2036
Total population :9.02292billion
year:2037
Total population :9.12398billion
year:2038
Total population :9.22617billion
year:2039
Total population :9.3295billion
year:2040
Total population :9.43399billion
year:2041
Total population :9.53965billion
year:2042
Total population :9.6465billion
year:2043
Total population :9.75454billion
year:2044
Total population :9.86379billion
year:2045
Total population :9.97426billion
year:2046
Total population :10.086billion


Related Solutions

Write a program in C (NOT C++ or C#) The program inputs 5 elements into each...
Write a program in C (NOT C++ or C#) The program inputs 5 elements into each of 2 integer arrays. Multiply corresponding array elements, that is, arrayOne[0] * arrayTwo[0], etc. Save the product into a third array called prodArray[ ]. Display the product array.
1. Write a program in C++ that takes as inputs a positiveinteger n and a...
1. Write a program in C++ that takes as inputs a positive integer n and a positive double a. The function should compute the geometric sum with base a up to the powern and stores the result as a protected variable. That is, the sum is: 1 + ? + ? ^2 + ? ^3 + ? ^4 + ⋯ + ? ^?2.  Write a program in C++ that takes as input a positive integer n and computes the following productsum...
C program, please Write a program that reads a sequence of 10 integer inputs and prints...
C program, please Write a program that reads a sequence of 10 integer inputs and prints the smallest and largest of the inputs and the number of even and odd inputs. for a beginner please, you could use a while loop,if-else,
Write a C++ program that inputs a sequence of integers into a vector, computes the average,...
Write a C++ program that inputs a sequence of integers into a vector, computes the average, and then outputs the # of input values, the average, and the values themselves. There are 0 or more inputs values, followed by a negative value as the sentinel; the negative value is not stored and not counted. The following sample input: 10 20 0 99 -1 would produce the following output: N: 4 Avg: 32.25 10 20 0 99 The main program has...
Write a C++ program that inputs a sequence of integers into a vector, computes the average,...
Write a C++ program that inputs a sequence of integers into a vector, computes the average, and then outputs the # of input values, the average, and the values themselves. There are 0 or more inputs values, followed by a negative value as the sentinel; the negative value is not stored and not counted. The following sample input: 10 20 0 99 -1 would produce the following output: N: 4 Avg: 32.25 10 20 0 99 The main program has...
Code in C Write a program whose inputs are three integers, and whose outputs are the...
Code in C Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the three values. Ex: If the input is: 7 15 3 the output is: largest: 15 smallest: 3 Your program must define and call the following two functions. The LargestNumber function should return the largest number of the three input values. The SmallestNumber function should return the smallest number of the three input values. int...
Write a C++ program that inputs two simplified poker hands (as defined in homework #5) and...
Write a C++ program that inputs two simplified poker hands (as defined in homework #5) and determines which (if either) of the hands is the winner, according to the following rules: • If the two hands have different types (3-of-kind, straight, pair, high-card), the hand with the better type (i.e., appears earlier in this list) wins. • If they have the same type, the higher significant card wins. • If the hands have the same type and significant card, there...
C++ in one program that ends with return 0} at the end f Write a program...
C++ in one program that ends with return 0} at the end f Write a program to calculate the salary paid to its salespersons at Pohanka. The salary is calculated based on a salesperson’s length of employment in years and employment category (full-time employee or part-time employee). The salary calculation rules are as following: 1) If an employee is a part-time employee and worked here for less than 5 years, the salary consists of only the commission amount; 2) If...
Write a program Write a program whose inputs are three integers, and whose output is the...
Write a program Write a program whose inputs are three integers, and whose output is the smallest of the three values. Ex: If the input is: 7 15 3 the output is: 3 C++ please
C++ Vector Write a program that allows the user to enter the last names of the...
C++ Vector Write a program that allows the user to enter the last names of the candidates in a local election and the votes received by each candidate. The program should then output each candidate's name, votes received by that candidate, and the percentage of the total votes received by the candidate. Assume a user enters a candidate's name more than once and assume that two or more candidates receive the same number of votes. Your program should output the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT