Does this program work, or is it my compilier?

Hello everyone, new guy on the forum here. I've looked all over youtube and google as well, but I cannot seem to find what is going on with my program. Essentially, what it is supposed to do is that the user inputs a number, lets say 12.2845. This is supposed to be a weight in kg. Then the program is to print kg and a converted kg into lbs, while limiting the decimal places to just 2 decimal places.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

#include <iostream>
#include <iomanip>
 
using namespace std; 

int main()
{
cout << "Enter a weight in kilograms to convert into pounds.\n\n";
double kg;
cin >> kg;
double lbs = kg * 2.2;
    std::cout<<std::fixed;
    std::cout<<std::setprecision(2);
    
    std::cout<<"kg = "<< kg;
    std::cout<<"lbs = "<< lbs;

  return 0;
}

Last edited on
But what doesn't work with it?

You can print an extra newline between line 16 and 17 to make it look nicer.
Last edited on
So my compiler is showing this:

Enter a weight in kilograms to convert into pounds.

12.3456
kg = 12
lbs = 27
lbs = 27.160320
Well, just to be clear: Your compiler doesn't run your program or output its code, you do. Your compiler just creates the program.

What compiler is it? If you're working in an IDE, try doing a "clean" of your project, there might be something misconfigured and it's using an older version of your code.
Well I'll be damned, I ran it in the program that this website has, and it does it correctly. I guess its just the shitty website that I am learning c++ on.
For about US$12 you can buy yourself a USB stick with a fairly large capacity. Then download and install Clang++ on it.

Unless your computer access is really locked down, you should be able to open the command prompt and do everything you want from the USB drive.

Oh, also. I recommend a good text editor, like Notepad++.

[edit]
Or something like Code::Blocks
Last edited on
Topic archived. No new replies allowed.