decimal problem

am not able to get the decimal value for k..instead of '0.5. its returning me 'o'

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 #include <iostream>
#include <vector>
using namespace std;
int main()
{
	double k , sum = 0;
	
	vector < int > s;
	int ar[1000][30];
	int a,b,i,c = 0;
	cin >> a;
	while ( a > c )
	{	
	   cin >> b;
	   for (int j = 0; j < b; j++)
	   {
		 for (i = 0; i < 3; i++)
		{
			cin >> ar[j][i];
		}
		k = ar[j][0] / ar[j][1];// k is not giving deciml value
		k = k * ar[j][2] * ar[j][1];
		cout << k << endl;
		sum = sum + k; 
		}
		s.push_back(sum);
		c++;
	}
	for (i = 0; i < a; i++)
	{
		cout << s[i] << endl;
	}
} 
Last edited on
ar[j][0] and ar[j][1] are both integers. Integer divided by integer is integer. Try this:

k = (1.0*ar[j][0]) / ar[j][1];
Last edited on
thanks,lb its work...
Topic archived. No new replies allowed.