I need help converting light years into astronomical.

Hi guys, i need help with my program. Basically i'm trying to convert light- years into astronomical units, but every time i run this program the astronomical units output is the same as the years.

#include <iostream>

double light_years(double);

int main(){

std::cout<< "please enter the light years: ";
double years;
std::cin>> years;
double light_years(years);
std::cout<< years <<" light years = " << light_years <<" astronomical units." << std::endl;

}
double light_years(double years){

return years * 63240;

}
double light_years(years);
This creates a variable of type double initialized with the value years named light_years which hides the function with the same name.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>

double to_astronomical_units(double);

int main()
{
    std::cout << "please enter the light years: " ;
    double years ;
    std::cin >> years ;
    std::cout << years << " light years = " << to_astronomical_units(years) << "au\n" ;
}

double to_astronomical_units(double light_years)
{
    return light_years * 63240 ;
}
thank so very much.
Topic archived. No new replies allowed.