cin >> [40];
We can't do that. You need to read into something that can store it.
cin >> speed;
Will get the speed entered by the user and store that value in
speed
(assuming the user didn't under something invalid, like a non-numeric character).
The same applies for reading in the km traveled.
If you want to just assign some value to it, you can do that
int speed = 40;
. The value of
speed
will be 40 to start with. The same applies to
km
In C++, diving two
int
s won't give you something with decimals. The division result will only contain the quotient and no remainder as a decimal.
5/7
in C++ will be 2, not 2.5.
1000/333
will be 3, not 3.003...
The same applies to any integral type (bool, char, short, int, long, long long), as they can only store whole numbers.
If you use floats/doubles, you can keep the remainder.
1 2
|
double speed;
double km;
|
Now doing
km / speed
will yield a result with decimals.