Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Issue with User Input

kayakinackkayakinack Posts: 2Member
When I call the following section of code, I get to the section to enter an integer for enter number of grades to drop and my program crashes.

[code]void Course::enterGCInfo(int num)
{
GradeCat tempGC;
string tempStr = "";
cout << "Enter Grade Category Name: ";
cin >> tempStr;
tempGC.setGCName(tempStr);
double tempDbl = 0.0;
cout << "Enter Grade Percentage: ";
cin >> tempDbl;
tempGC.setGCPerc(tempDbl);
int tempInt = 0;
cout << "Enter Number of Grades To Drop: ";
cin >> tempInt;
tempGC.setNumToDrop(tempInt);
setGradeCat(num,tempGC);
refresh();
}[/code]

This is the error message:
[code]Unhandled exception at 0x004149eb in Grade Tracker.exe: 0xC0000005: Access violation reading location 0x3343f1c8.[/code]

I'm using Visual Studio 2010 Express - Start Debugging. When it reaches this error it takes me to following code in file xstring

[code] bool _Grow(size_type _Newsize,
bool _Trim = false)
{ // ensure buffer is big enough, trim to size if _Trim is true
if (max_size() < _Newsize)
_Xlen(); // result too long
if (this->_Myres < _Newsize)
_Copy(_Newsize, this->_Mysize); // reallocate to grow
else if (_Trim && _Newsize < this->_BUF_SIZE)
_Tidy(true, // copy and deallocate if trimming to small string
_Newsize < this->_Mysize ? _Newsize : this->_Mysize);
else if (_Newsize == 0)
_Eos(0); // new size is zero, just null terminate
return (0 < _Newsize); // return true only if more work to do
}[/code]

The cursor stops next to this line:
[code]if (this->_Myres < _Newsize)[/code]

The function calls dealing with that Integer input

setNumToDrop
[code]void GradeCat::setNumToDrop(int num)
{
numToDrop = num;
}[/code]

setGradeCat
[code]void Course::setGradeCat(int num,GradeCat tempGC)
{
GCs[num] = tempGC;
}[/code]

GCs is an array of GradeCat objects

refresh
[code]void Course::refresh()
{
calcGrade();
calcTotalPerc();
sortGradeCats();
}[/code]

Comments

  • kayakinackkayakinack Posts: 2Member
    umm, you'll have to put that into so easier language to me to understand.

    Anyway, I figured out my problem, I knew it would be something stupid. I was not sending a proper value to the function, so that improper value was being used to insert an object into an array. DOH!
  • ciomalauciomalau Posts: 4Member
    why all = faknob? i want know! :(
  • ciomalauciomalau Posts: 4Member
    i see how they = st00pid but they all die... :(

    man listen i want to start creating my own games in C++ using directx9. but i'm right at the start! i'm barely at chapter 4 from Thinking in C++. and i have some questions about what i learned. so take this as an example

    void (*funcptr)();
    //so this is a pointer to a function which takes no arguments and returns void

    void* funcptr2();
    //a function which returns a pointer to void

    void* (*(*fp1)(int))[10];
    //fp1 is a pointer to a function which takes an int an returns a pointer to an array of 10 pointers to void

    float (*(*fp2)(int,int,float))(int);
    //fp2 is a pointer to a function which takes 3 arguments and returns a pointer to a function which takes an int and returns float

    i can read most of these expressions using the middle-right-left-right-etc method described in the book. but i'm not sure i can use this stuff - it seems too complicated. so if i take up game programming would i bump often into such things?

    PS i now mother not home but she come late ok?
Sign In or Register to comment.