how to round ?

the question is requiring me to write a program that produces a bar chart showing the yearly income of a small company starting 1990. The program reads the income figures (rounded to the nearest $1,000) from a file called “income.txt”. For each year it should display the date and a bar consisting of one star („*‟) for each $1,000
i did everything except the rounding i tried the integer division but it didn't work

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
int main()
{
double income[100],date=1990;
int j=0 ,s;

ifstream If ("D:\\income.txt");
while (If>>income[j])
{
cout<<date;

s=income[j]/1000;
for(int i=1 ; i<=s ; i++ )
cout<<"*";

j++;
date++;
cout<<endl;
}
return 0;
}
For positive values you may add 500 and for negative values -500:

1
2
3
4
if(income[j] < 0)
  s=(income[j] - 500) /1000;
else
  s=(income[j] + 500) /1000;
thanks for your help, i really appreciate it :):)
Topic archived. No new replies allowed.