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...
In c++ language, write a void function GetYear that prompts for and inputs the year the...
In c++ language, write a void function GetYear that prompts for and inputs the year the operator was born (type int) from standard input. The function returns the user’s birth year through the parameter list (use pass by reference) unless the user enters an invalid year, in which case a BadYear exception is thrown. To test for a bad year, think about the range of acceptable years. It must be 4 digits (i.e. 1982) and it cannot be greater than...
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...
Write a short and simple C++ program (must be able to have custom inputs): Design a...
Write a short and simple C++ program (must be able to have custom inputs): Design a class that holds the following personal data: name, address, age, and phone number Write appropriate accessor and mutator functions. Demonstrate the class by writing a program that creates three instances of it. One instance should hold your information, and the other two should hold your friends' or family members' information. Thanks!!
Write a C++ program that inputs three integers in the range [1..13] that represent a hand...
Write a C++ program that inputs three integers in the range [1..13] that represent a hand of three cards. Your program should output an English evaluation of the hand. In the output, cards will be described as follows: - 2–10 are described by the words for their numeric values: two, three, etc. - 1 is called an ace, 11 is called a jack, 12 is called a queen, and 13 is called a king. The evaluation of a hand is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT