HOW DO I ROUND THE OUTPUT?



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  while(!fin.eof())
	{
		for(int n=0;n<43;n++)
		{
			tempo.statename[n]=temp.name;
			tempo.admission[n]=temp.order;
			tempo.density[n]=temp.population/temp.area;
			
		fin.read((char*)&temp,struct_size);
		}
	}

THE DENSITY=POPULATION/AREA;

ALASKA DENSITY

400481/586400=0.6829

//when I run the program it gives me 0 as a density. How can I round 0.6829 to 1.

My professor said use int for density.
closed account (4NqL8vqX)
tempo.density[n]=temp.population/temp.area;


It should be :
tempo.density[n] = temp.population / (double)temp.area;
Use the function round() from <math.h> float n2 = round(DENSITY);
Last edited on
closed account (4NqL8vqX)
Then you use this :
tempo.density[n] = round(temp.population / floor(temp.area));
Topic archived. No new replies allowed.