# Can someone help me to solve these two coding questions?

Hi guys I’m new to programming can someone help me to solve these two coding questions?

1- Create a program that takes in the weight of an item and then calculates how much that item would weigh on Mars.

2- Create a program that asks for a distance in miles as input. The program will then output how much that distance is in kilometers.

I solved the first one but I think it’s wrong.

#include

int main() {
int weight;
double weight_on_mars;

``````std::cout << "Enter the weight of the object: " << std::endl;

std::cin >> weight_on_mars;

weight_on_mars = (weight / 9.81) * 3.711;

std::cout << "The object would be " << weight_on_mars << " on mars." << std::endl;

return 0;
``````

}

You have

``````std::cin >> weight_on_mars;
``````

but I think you want the user to enter the weight on Earth, so it that should actually be

``````std::cin >> weight;
``````
2 Likes

Hello, I have attached the code to the second problem you had asked about with some explanations. Please let me know if you have any questions.

``````> #include <iostream>
> #include <iomanip> // this library allows for setting the decimal point precision.
> using namespace std;
>
> int main() {
>   double miles = 0; // This is also a double because it is giving you the option to convert decimal miles not just whole numbers.
>   double kilometers = 0; // Here this would be a double because the conversion to kilometers will not yield a whole number most likely.
>
>   cout << "Enter distance in miles" << endl;
>   cin >> miles;
>
>   kilometers = miles * 1.609; // conversion
>
>   cout << fixed << setprecision(3)<< kilometers << " kilometers"; // This allows for the number of decimal points in the answer to be restricted to 3 or less.
> }
``````