More user defined madness

Jan 21, 2011 at 6:55pm
hey guys, trying my hand at user defined functions once again, and this program works!....... errrr, well........ depends on your definition of "works", lol, anyways, feel free to plug in my goofy ass program to your compiler and tell me what you think, i believe my math function may be written incorrectly, because the output is some sort of characters, definately not what im looking for in my output....... here it is, lemme know what im doing wrong, thanks guys...........


//program to convert light years to astronomical units

#include <iostream>
#include <cmath>
double lightyear ();
double astronomical (double);

int main()

{



std::cout<< "Enter The Distance in Light Year(s):";
double lightyear;
std::cin>> lightyear;
double astronomical(double astronomical);
std::cout<< "Thats a distance of:"<< astronomical <<"units!"<<std::endl;
std::cout<<"Well, better get going because this will be a lonnnng trip!"<<std::endl;

std::cin.get();
std::cin.get();

return 0;

}

double astronomical(double sts)

{
return 63,240 * sts;

}
Jan 21, 2011 at 6:57pm
ps one light year=63,240 astronomical units...
Jan 21, 2011 at 7:05pm
Fixes.

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
26
#include <iostream>
// don't need <cmath>
//double lightyear (); // Never used.
double astronomical (double); // This is fine

int main()
{
  std::cout << "Enter The Distance in Light Year(s): ";
  double lightyear; // Shouldn't have a variable with the same name as a function
  std::cin >> lightyear;
  //double astronomical(double astronomical); // What is this? Delcaration?
  // ^ You already declared a function above.
  std::cout << "Thats a distance of: " << astronomical( lightyear ) << " units!" << std::endl;
  // ^ How you correctly call the function. You are expecting it to return the value.
  std::cout << "Well, better get going because this will be a lonnnng trip!" <<std::endl;

  std::cin.get();
  std::cin.get();

  return 0;
}

double astronomical(double sts)
{
  return 63,240 * sts;
}


Jan 21, 2011 at 7:20pm
ahhhh ok, coool, derrrp, yea my original issue was below the input i had defined astronomical again, figured that out and deleted it but then ran into this........ ok gotchya, thanks man, and definitely appreciate the comments, always helps when people explain what i did wrong instead of just correcting it
Jan 21, 2011 at 7:28pm
still doesnt return the valid number, gonna try something else
Jan 21, 2011 at 7:29pm
ok got it now, dumb mistake, computer didnt recognize the comma separating the numbers..... got rid of it and now the math is correct
Topic archived. No new replies allowed.