Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Read in two variables, year and population. Each year the population increases b

ID: 641608 • Letter: R

Question

Read in two variables, year and population. Each year the population increases by 10%. Write a program that displays the annual population and stops in the year when the town will count over 100,000 people.

Make sure that the population is positive, non-zero.

For example:

What I tried:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main() {
  
float i=0.10;
int n=0;
int p;
int Year;
float Pop;   
  
scanf("p=%d year=%d ", &p, &Year);

while (Pop<=100000 && Pop>0){

Pop=p*pow((i+1),n++);}
printf("%f",Pop);
if(Pop>0){
printf("Year Population ------------------ ");
printf("%d %.2f ", Year, Pop);
}
  
else if (p<=0)
printf("Population must be larger than 0");
return 0;
}

Input Output p=87650 year=2013 Year   Population
------------------
2013   87650
2014   96415 p=-4 year=2013 Population must be larger than 0

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(){
   int p;
   int year;
   printf("Enter population: ");
   scanf("%d", &p);
   while(p <= 0){
       printf("Population can not be negative. Enter again! ");
       printf("Enter population: ");
       scanf("%d", &p);
   }
   printf("Enter year: ");
   scanf("%d", &year);
   while(p < 100000){
       year++;
       p += (p * 0.1); // (p * 0.1) is 10 percent of the current population
   }
   printf("Population has crossed 100000 ");
   printf("Population in %d is %d ", year, p);
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote