C++ code not working

I am trying to write a small c++ program as a bit of practice, but I can’t seem to get it to work. When I attempt to run it, I don’t get a result. Here is my code.

#include <iostream>

int main() {
 
//variables below  
double distancemi;
double distanceme;

std::cout << "MILES TO METERS CONVERTER\n";
std::cout << "\n"; //not sure if this is proper way to skip line :/
std::cout << "ENTER DISTANCE IN MILES - \n";

std::cin >> distanceme;
//complicated calculations below
distanceme = distancemi * 1609;

std::cout << distancemi << "MILES IS EQIVALENT TO" << distanceme << "METERS\n";
}

Thanks in advance :slight_smile:

distanceme = distancemi * 1609;

I think you wanted your variables the other way around. distancemi is never initialized so it defaults to 0, which then gives you 0 in the output regardless of what input you enter.

2 Likes

Thanks for the help! I need to pay closer attention to this stuff in the future…

1 Like