I think its probably your second or third program, and you have nothing to worry about. I see good habits, you used std:: which is already better than 95% of new coders. I see some comments to help understand it, which is good as well.
Variable names help twice over, once to make it easier to read, and they eliminate comments.
consider
int y; // y is the kilograms
int kg; //self explanatory... no comment needed here?
It would be better using code tags, <> on the side bar editor. Try to do that going forward.
Lets give it a rewrite for fun. I added some prompts to tell user what to do, named variables as to what they are doing, added constants instead of 'magic numbers' that have unclear meaning.
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
|
// kilogram1.cpp : This file contains the 'main' function. Program execution
//begins and ends there.
#include <iostream>
int main()
{
constexpr double km2mi = 0.621371;
constexpr double kg2lbs = 2.204623; //same # of decimals for consistency
std::cout << "Hello, I am Ghadeer !\n";
int km;
std::cout << "Please input a value in km to convert to miles>";
std::cin >> km;
std::cout << km * km2mi; // this is to convert kilometer to miles
int kg;
std::cout << "Please input a value in kg to convert to pounds>";
std::cin >> kg;
std::cout << kg * kg2lbs ; // this is to convert kilogrms to pounds
std::cout << " Thank you for using this program!";
return 0;
}
|
see how you can follow without excess comments? Its clear that
std::cout << kg * kg2lbs ; // this is to convert kilogrms to pounds
you are printing pounts from kilos here, because the variables tell you that, making the comment silly.
Even though I changed a little, I still think you did well for an early program. The changes are just stuff to think about for next time.