Help with showing decimal points

Hi I have to do this assignment where I convert KMH to MPH, and the result needs to be a decimal place. This is what I have so far.

1
2
3
4
5
6
7
8
9
10
#include <iostream>


int main() {
   std::cout << "Enter your speed in kilometers per hour:\n"; 
   int kph; 
   std::cin >> kph; 
   int result = float(kph * 0.6214);
   std::cout << "Your speed in miles: " << result << "\n";
}
You need to use floating point variables. double is a good choice. And you might want to set it to output a fixed number of decimals.

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <iomanip>

int main() {
   std::cout << "Enter your speed in kilometers per hour:\n"; 
   double kph;
   std::cin >> kph;
   double result = kph * 0.6214;
   std::cout << std::fixed << std::setprecision(2);
   std::cout << "Your speed in miles: "
             << result << '\n';
}

Ok it works now, thanks
Topic archived. No new replies allowed.