Need help

Need help? Because the loop not function. The Year supposed increase from 2013 till 2017, but its not done.

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

main()
{
int Year;
int inipop, projpop;
int growth, sum;

printf("\n Please enter number of initial population: ");
scanf("%d",&inipop);

printf("\n Please enter the projected of population: ");
scanf("%d",&projpop);

printf("\nThe increase Year of Population: \n");

{
for(Year = 2013; Year <2017; Year++)

growth = inipop + projpop;

printf("%d %d\n",Year,growth*2);
printf("%d %d\n",Year,growth*3);
printf("%d %d\n",Year,growth*4);
printf("%d %d\n",Year,growth*5);
printf("%d %d\n",Year,growth*6);
}

getch();
return 0;

}

Out Put;

Please enter number of initial population: 2000

Please enter the projected of population: 200

The increase Year of Population:
2018 4400
2018 6600
2018 8800
2018 11000
2018 13200

Last edited on
1
2
3
4
5
6
7
8
9
10
11
{
for(Year = 2013; Year <2017; Year++) 

growth = inipop + projpop;

printf("%d %d\n",Year,growth*2);
printf("%d %d\n",Year,growth*3); 
printf("%d %d\n",Year,growth*4); 
printf("%d %d\n",Year,growth*5); 
printf("%d %d\n",Year,growth*6);
}


u have misplaced brace
1
2
3
4
5
6
7
8
9
10
for(Year = 2013; Year <2017; Year++) 
{
growth = inipop + projpop;

printf("%d %d\n",Year,growth*2);
printf("%d %d\n",Year,growth*3); 
printf("%d %d\n",Year,growth*4); 
printf("%d %d\n",Year,growth*5); 
printf("%d %d\n",Year,growth*6);
}

Hi anirudh sn,

Thanks, the reply. But the output still wrong. Any suggestion to make right?

OUTPUT

Please enter number of initial population: 2000

Please enter the projected of population: 200

The increase Year of Population:
2013 4400
2013 6600
2013 8800
2013 11000
2013 13200
2014 4400
2014 6600
2014 8800
2014 11000
2014 13200
2015 4400
2015 6600
2015 8800
2015 11000
2015 13200
2016 4400
2016 6600
2016 8800
2016 11000
2016 13200
2017 4400
2017 6600
2017 8800
2017 11000
2017 13200


The output supposed;

2013 4400
2014 6600
2015 8800
2016 11000
2017 13200
there is something wrong with ur logic, if u can give the problem statement, and what ur trying to achieve, i can help u.
According to my program, how to make the output as below?

2013 4400
2014 6600
2015 8800
2016 11000
2017 13200
Well, the problem is that you have 5 printf statements on each cycle of the loop. If you only want it to print once per loop cycle, why do you have five?
Hi MikeyBoy;

Thanks, the reply. If one print only, i got the result as below. The value start 2013 till 2017 is same = 4400. I need help how to integrate the program which the output value is different with every year starting from 2013. Any suggestion how to make it?

2013 4400
2014 4400
2015 4400
2016 4400
2017 4400
Last edited on
That's because at the start of each iteration of the loop, you're resetting the value of growth to the same value. You need to change the logic of your algorithm so that each iteration of the loop increases the value of growth from its previous value, rather than resetting it to the same value as it was on the previous iteration.
Can you help me, to show in program? Please use the program above. Your help very appreciated.
I can help, but I'm not going to write the code for you. Thinking about the logic of algorithms is a vitally important part of programming, and it's a skill all programmers need to practise.

Can you see where in the code you're setting the value of growth?

Do you understand why this value is the same on every iteration of your loop?

Can you think how you might change the way you calculate the value of growth, so that it gives you the right value on each iteration of the loop?
I do many times try to created the right logic of algorithms, but an impasse. I don't know how to used the result to put back in the formula. I just need simple code from you to show me how the logic of algorithms can give the result according to the proper output. Or just show the other way. That why, i need somebody can guide me with the a little touch which can correct my program.
Topic archived. No new replies allowed.