Menu

another, strange problem with my dev on vista

codor kim
2008-04-25
2012-09-26
  • codor kim

    codor kim - 2008-04-25

    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?

     
    • Curtis Sutter

      Curtis Sutter - 2008-06-12

      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.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.