Personally I think your issue is with "int DoubleCheeseburgers = 40;" being private and not public. By defining it in the main{} scope, it should be limited to that. I would simply pass the value (or reference) to the EatAtJoes() function. However, it has been some time since I have do any C++ programming and could be wrong.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
hello everyone, i ran into another problem with my dev c++ on vista.
i followed my book in the creation of this sample program with 3 files:
1. main:
include <cstdlib>
include <iostream>
include "sharealike.h"
using namespace std;
int main(int argc, char *argv[])
{
int DoubleCheeseburgers = 40;
EatAtJoes();
system("pause");
return exit_success;
}
2. sharealike.h:
include <iostream>
include <cstdlib>
using namespace std;
extern int DoubleCheeseburgers;
void EatAtJoes();
3. sharealike.cpp
include <cstdlib>
include <iostream>
include "sharealike.h"
using namespace std;
int DoubleCheeseburgers;
void EatAtJoes() {
cout << "how many cheeseburgers today?" << endl;
cout << DoubleCheeseburgers << endl;
}
supposely when i compile and run the program i should get
how many cheeseburgers today?
40
printed on the console. but instead i got
how many cheeseburgers today?
0
0? what went wrong? and i can assign 20 or any number to "int DoubleCheeseburgers" in the main file and still get 0. can you guys help me?
Personally I think your issue is with "int DoubleCheeseburgers = 40;" being private and not public. By defining it in the main{} scope, it should be limited to that. I would simply pass the value (or reference) to the EatAtJoes() function. However, it has been some time since I have do any C++ programming and could be wrong.