extern trouble

Hi. I'm writing a horse racing analysis program. Here is my code that is giving me trouble: note 2 functions and the header file
The function void raceDistance(), inputs the distance of the race(input by user).
the function void test(), then prints out the distance(for testing purposes here). However I do not get the number that I put in to the 'distance' variable.
I get a very large number. It's obvious that my program does not accept my global variable declaration. Suggestions?


//First function:
#include <cstdlib>
#include <iostream>
#include "myVariables.h"
using namespace std;
void test();
void raceDistance()
{
double distance;
cout << "\nEnter race distance; press enter: ";
cin >> distance;
test();
}

//Second Function:

#include <cstdlib>
#include <iostream>
#include "myVariables.h"

using namespace std;

void test()
{
double distance;
cout << "\nraceDistance is: " << distance;
}

//Header File:(myVariables.h)

extern double distance;


In one of those, the functions, distance needs to have another extern. It's a pain in the backside, I know, but you need it.

-Albatross
Topic archived. No new replies allowed.