Integer won't hold decimels

I'm just starting out with C++, and I'm experimenting with different functions and uses. And this particular program is supposed to calculate how much gas you should put in your car based on how far you just traveled.

The user enters the value for PirceOfGas, but when it comes time later to calculate how much gas must be put in the car, the math is completely off and I cannot figure out why. Also, when it is supposed to output the value of PriceOfGas the decimel isn't there, just the first (whole) number.

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
34
#include "stdafx.h"
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <Windows.h>

using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
	int DistanceTraveled;
	int MPG;
	int PriceOfGas;
	int GasUsed;
	int GasToPutIn;

	cout << "How many miles did you travel?" << endl;
	cin >> DistanceTraveled;

	cout << "What is the cost of gas?" << endl;
	cin >> PriceOfGas;
	
	GasToPutIn = DistanceTraveled * PriceOfGas;

	MPG = 20;
	GasUsed = DistanceTraveled / MPG;

	Sleep(1300);

	cout << "You traveled " << DistanceTraveled << " miles and used " << GasUsed << " gallons of gas." << endl;
	cout << "If gasoline costs $" << PriceOfGas << " you must put in $" << GasToPutIn << "of gas." << endl;

	system("PAUSE");
	return 0;
}
And how exactly is that surprising?
http://en.wikipedia.org/wiki/Integer

Use double.
Topic archived. No new replies allowed.