Thread: Visual Studio Just-In-Time Debugger Error

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    1

    Visual Studio Just-In-Time Debugger Error

    Hello everybody I'm in the middle of programming a basic console application that is supposed to be a stock market game for my programming class in c++. I have run into this weird error involving a Visual Studio Just-In-Time Debugger window popping up saying I have a Win 32 unhandled exception even though I am using Code::Blocks 10.05 as my IDE, not Visual C++.

    Attachment 10148

    Now my whole project is rather long(at least from my point of view) so far but basically what happens is that I have a main function, a class named CStock(which is what the stocks in my game are made from) and then a bunch of other functions that make up different parts of the program (generating a random number, publishing the prices to the console, and some others).

    I had started out declaring the different stocks after the Class using their names (Gold, Silver, Beef, etc), but then I wanted to declare them as an array instead so that it would be easier to add or change the amount of stocks I had in the game.

    Once I changed to declaring the stocks after the class as an array, however, I got the error. I do not receive the error if I declare the array of stocks during a seperate function (not directly after the class), but then I cannot access the array of stocks in all the functions of my program.

    Here Is my code so far and I would greatly appreciate any help/ advice anyone has to offer.

    Code:
    //This class creates a stock with the initial name and value inputted
    class CStock
    {
            public:
                int iPrice, iTrend, iChange, iAmountOwned;
                string sStockName;
                CStock();                      //constructor
    
                void ChangePrice()
                //changes this stock's price
                {
                    int iRanNum;
                    iRanNum = RandomNumber(-50, 50);
                    //iRanNum = (rand() % 101) - 50;
                    iPrice+=iRanNum;
                    iChange=iRanNum;
                    iTrend+=iRanNum;
                };
    
                void PublishPrice()
                //publishes the current info for this stock
                {
                    cout<<sStockName<<" Price: "<<iPrice<<" Change: "<<iChange<<" Trend: "<<iTrend<<endl;
                };
    
                void Buy(int iAmountToBuy)
                //Buys an amount of stocks for the user
                {
                    int iTotalCost;
                    //calculates total price
                    iTotalCost=iAmountToBuy*iPrice;
                    //only buys the stocks if you have enough money too
                    if(iUserMoney>=iTotalCost)
                    {
                    iUserMoney=iUserMoney-iTotalCost;
                    iAmountOwned+=iAmountToBuy;
                    cout<<endl<<"Money: "<<iUserMoney<<" "<<sStockName<<" Owned: "<<iAmountOwned<<endl;
                    }
                    else{cout<<endl<<"Get more money you hobo!"<<endl;};
                };
    
                void Sell(int iAmountToSell)
                //Sells an amount of stocks for the user
                {   //only sells if you input a valid amount to sell
                    if(iAmountOwned>0 && iAmountToSell<=iAmountOwned)
                    {
                        int iMoneyEarned;
                        //calculates how much money you will earn and adds it to user's total money
                        iMoneyEarned=iAmountToSell*iPrice;
                        //as well as subtracting the amount of stocks that were sold
                        iAmountOwned-=iAmountToSell;
                        iUserMoney+=iMoneyEarned;
                        cout<<endl<<"Money: "<<iUserMoney<<" "<<sStockName<<" Owned: "<<iAmountOwned<<endl;
                    }
                    else{cout<<endl<<"You cannot sell that many!"<<endl;}   //outputs this message if an invalid amount is tried to be sold
    
                }
    
                void SetValues(string InpStockName, int InpPrice, int InpAmountOwned)
                //this function sets the values for the stock
                    {
                        sStockName = InpStockName;
                        iPrice = InpPrice;
                        iAmountOwned = InpAmountOwned;
                    }
    }Stock[4]; //this causes the error when declared here******************************************************************
    //CGold("Gold", 1000), CSteel("Steel", 1000), CBeef("Beef", 1000), CWheat("Wheat", 1000), CSilver("Silver", 1000);
    
    
    
    //Stock class constructor that sets the values to default before they are specified
    CStock::CStock()
            {
                sStockName = "unnamed";
                iPrice = 1000;
                iTrend = 0;
                iChange = 0;
                iAmountOwned = 0;
            };
    void SetStockValues()
    //this sets the values for all the declared stocks
    {
        //CStock Stock[4]; no error when declared here, but only usable within this function**************************************************
        Stock[0].SetValues("Gold", 1000, 0);
        Stock[1].SetValues("Silver", 1000, 0);
        Stock[2].SetValues("Beef", 1000, 0);
        Stock[3].SetValues("Wheat", 1000, 0);
        Stock[4].SetValues("Steel", 1000, 0);
    }
    edited for linesize and readability. -nv

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It means that you have Visual Studio installed and it is set to catch errors that occurs (instead of the "this program has done something illegal and needs to be closed") and offers to launch a debugger to see where the error lies.
    In other words, your program crashed.

    So I suggest you open up C::B and launch it in a debugger or using Visual Studio to find out where the error occurs. Then backtrace to find the problem.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  4. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  5. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM

Tags for this Thread