raptr_dflo 48 Posting Pro

robdb,

First, am I correct in assuming that your program is reading in the whitespace-separated words from one file, and writing out encoded versions of the words one-per-line?

If that's the case, first, you're sizing index_t array incorrectly. You don't want an index-entry per word in your file, you want an index-entry per character in your string. If you use vector<int> instead of a C-style int-array, the compiler (or the vector<> class, really) will take care of making sure it's as big as you need to store each encoded string as you encounter it. Otherwise, keep track of the currently-allocated size of index_t and whenever you get a string longer than that, reallocate it to be long enough for that string.

Other than that, what value do you store in index_k or index_t if the character isn't in your ALPH set?

Finally, since it doesn't look as though you access index_t outside of your for(i...) loop, you don't need to maintain an array of indices for the word anyway -- just compute the encoded letter and write it to your output file..

But I think maybe you're hacking away at the problem instead of thinking through each step, and what needs to happen as part of that step.

Since you've already written "read an input file into a list-of-strings" functionality, then write some kind of "write a list-of-strings to an output file" functionality, and test that if you just write out the same list …

raptr_dflo 48 Posting Pro

and for your system()-call example, try something like this:

string cmd;
cout << "What command would you like to run?" << endl;
cin >> cmd;

cout << "Trying to run: system(\"" << cmd << "\")" << endl;
system(cmd.c_str());
raptr_dflo 48 Posting Pro

For what it's worth, I'm set up to use the MinGW gcc compiler, and the top of my gl.h file reads:

/*
 * Mesa 3-D graphics library
 * Version:  4.0
 *
 * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
...
raptr_dflo 48 Posting Pro

I'm getting a NULL-ptr returned from glGetString() also, and glGetError() returns x502 (INVALID_OPERATION) ... still looking into that.

As far as the texture coordinate thing, my typo sorry. That should have read:

glTexCoordPointer(2, GL_FLOAT, sizeof(glVertexStructure), &(vars[0].text[0]));
...
glNormalPointer(GL_FLOAT, sizeof(glVertexStructure), &(vars[0].norm[0]));
raptr_dflo 48 Posting Pro

I'm looking at section "23.070 How can I call extension routines on Microsoft Windows?" of the OpenGL FAQ. It looks like what you're already doing, but if you're getting undefined symbols with GOODGL defined, then those functions are presumably not in your opengl32.lib, and if you're getting NULL pointers back from wglGetProcAddress(), then they're not defined in your device's ICD either ... which indicates that your graphics hardware doesn't support the glGenBuffers() call -- also from the OpenGL website,

Notes: glGenBuffers is available only if the GL version is 1.5 or greater.

Also see this to find out what version of OpenGL you're running, and the question immediately below it if you suspect you're seeing weird behavior (picking unaccelerated pixel formats).

raptr_dflo 48 Posting Pro

Should line 446 above read something more like:

double frametime = 1000.0/(double)window.fps;
if (deltatime < frametime)
    Sleep(frametime-deltatime);

You can ignore what I said previously about glSwapBuffers, GL.Update() clearly does that, but you still need to draw into the other buffer, so your do {} while (); loop needs to clear, draw and Update() each time.

While you haven't gotten that far yet (past Compile()), unless you got your glGenBuffersD (etc.) pointers to be non-null, you're going to run into potential problems in model.Draw() where you call

...
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glTexCoordPointer(2,GL_FLOAT,sizeof(glVertexStructure),(void*)((char*)(NULL)+sizeof(float)*(&(vars[0].text[0])-&(vars[0].vert[0]))));
    ...

if you haven't already called GL.LoadTexture() and GL.SetTexture().

The safest thing to do is probably pass the texture file into a model.AttachTexture() method which calls GL.LoadTexture(), and have the model maintain its texid. Then you can use whether the texid is non-zero to decide whether to call GL.SetTexture() and provide tex-coords.

Also, I think the offset to the first texture coordinate is probably as simple as:

glTexCoordPointer(2, GL_FLOAT, sizeof(glVertexStructure), &(vars[0].vert[0]));

and similar for the first normal coordinate.

But we still gotta figure out why you can't Compile(). If the pointers are NULL, we have to go back to where you assign them in genfunc(). If they're NULL there, then there's something wrong with how you're looking them up.

raptr_dflo 48 Posting Pro

For the errors (lines 14-17 of your output above), try wrapping line 10 of your code, replacing:

#include <gl/glext.h>

with

extern "C" {
    #include <gl/glext.h>
}

We can deal with the warnings later, but I think the first one might relate to your constructor-from-filename: vars and numv don't get initialized at all if you fail to open the file. For the signed vs. unsigned cases, when you're looping over the vars, since numv is declared to be unsigned, declare i to match.

As far as your clear (not black) screen ... try setting your glClearColor to opaque:

glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

Also, since I don't know what GL.Update() does, perhaps your do{} loop needs to do something like:

do {
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  model.Draw();
  GL.Update();
} while (!GL.window.key[VK_ESCAPE]);

and if you have double-buffering enabled (you requested it in your pfd variable, but I don't think you ever check on return whether you actually got it), you probably need a glSwapBuffers(); call somewhere as well.

raptr_dflo 48 Posting Pro

Haha, oops. die() doesn't write its argument into the file! Line 190 should read: WriteData( s ); , not WriteData( "%s" );. Then you might get something useful. Sorry I missed that before! :)

raptr_dflo 48 Posting Pro

I think the PDB messages are warnings (about not being able to find debug symbols should you wish to use the debugger to see where the problem is) -- see the second response here for more info.

Other than that, the only actual "error" is that your program exited with code -1, which is exactly what the die() function does. Do you now have a File1.txt file? What messages are in it?

raptr_dflo 48 Posting Pro

Its as if the "start" value takes the SDL_GetTicks value and then sets to 0 after it does his thing

What makes you think this is the case?

From the tutorial description text:

So if you started the timer when SDL_GetTicks() was 10,000 and now SDL_GetTicks() is 20,000, it will return 10,000 meaning 10 seconds have passed since the timer started.

Meaning SDL_GetTicks() is returning values in units of milliseconds, not seconds. Perhaps this is the source of confusion? Since the code calls the rendered text-surface "seconds", it might be more obvious if you convert to the expected units:

...
    time << "Timer: " << (SDL_GetTicks() - start)/1000;  // or use 1000.0 to see fractions of seconds
    seconds = TTF_RenderText_Solid( font, time.str().c_str(), textColor );
    ...
raptr_dflo 48 Posting Pro

I'm not seeing anything obvious at this point. One question is, at line 38 of GL.Init() above, you initialize pfd to include ... PFD_TYPE_RGBA, bpp, ... , but you're passing 24 in for bpp. Did you mean either to pass in 32, or to specify PFD_TYPE_RGB? Or will ChoosePixelFormat() do the right thing for you?

Other than that, to ensure that GL.Init() is actually working (at least a little), try commenting out the model.Draw(); line, and you should get a running app with a blank black screen. If that works, I'm worried that your looked-up function addresses are still wacky. Try printing out those pointer addresses and see if they make some sense:

printf("glGenBuffersD ptr = %p\n", glGenBuffersD);

Or if your compiler doesn't support %p (and you're building a 32-bit application), try:

printf("glGenBuffersD ptr = 0x%08x\n", (unsigned long)glGenBuffersD);

Other thoughts:
Why are you creating a default quadricobject in GL.Init()?
Should you be enabling GL_TEXTURE_2D if you're not creating and applying a texture-map?

raptr_dflo 48 Posting Pro

Hmmm... I suspect the memory you're corrupting isn't where you think it is. Can you post your main() that you're testing this against also?

raptr_dflo 48 Posting Pro

Are you also going to remove the leading declarations in genfunc(), now in lines 45-48?

raptr_dflo 48 Posting Pro

For convenience, I'm posting the main() routine from the tutorial (as provided in the download link), so we can refer to the same line numbers:

int main( int argc, char* args[] )
{
    //Quit flag
    bool quit = false;

    //The timer starting time
    Uint32 start = 0;

    //The timer start/stop flag
    bool running = true;

    //Initialize
    if( init() == false )
    {
        return 1;
    }

    //Load the files
    if( load_files() == false )
    {
        return 1;
    }

    //Generate the message surface
    startStop = TTF_RenderText_Solid( font, "Press S to start or stop the timer", textColor );

    //Start the timer
    start = SDL_GetTicks();

    //While the user hasn't quit
    while( quit == false )
    {
        //While there's an event to handle
        while( SDL_PollEvent( &event ) )
        {
            //If a key was pressed
            if( event.type == SDL_KEYDOWN )
            {
                //If s was pressed
                if( event.key.keysym.sym == SDLK_s )
                {
                    //If the timer is running
                    if( running == true )
                    {
                        //Stop the timer
                        running = false;
                        start = 0;
                    }
                    else
                    {
                        //Start the timer
                        running = true;
                        start = SDL_GetTicks();
                    }
                }
            }

            //If the user has Xed out the window
            else if( event.type == SDL_QUIT )
            {
                //Quit the program
                quit = true;
            }
        }

        //Apply the background
        apply_surface( 0, 0, background, screen );

        //Apply the message
        apply_surface( ( SCREEN_WIDTH - startStop->w ) / 2, 200, startStop, screen );

        //If the timer is running
        if( running == true )
        {
            //The timer's time as a string
            std::stringstream time;

            //Convert the timer's …
raptr_dflo 48 Posting Pro

Since you say:

I have build all automatically selected.

I imagine you have to go into the portion of the interface which deals with setting up your build. I'm not familiar with the Galileo Eclipse IDE, so I can't help with any details, but there should be a way to add additional source files to your build, and (if necessary) a way to specify how to assemble your .s file into a .o file.

raptr_dflo 48 Posting Pro

Now that you're using instance members for your GL function pointers, remove lines 9-12.

In genfuncs() (lines 49-52), you're declaring local variables that mask your class members, so that when you get to Compile(), the function-ptr members are still uninitialized. Omit the leading type-names, e.g.:

glGenBuffersD = (PFNGLGENBUFFERSARBPROC)wglGetProcAddress("glGenBuffersARB");

You should probably also check, at the top of Draw(), that your model actually contains something (numv > 0). I'm not sure what the functions in Compile() will do if you pass 0 vertices and a NULL ptr.

Hopefully this will get you past the immediate problem with Compile()!

raptr_dflo 48 Posting Pro

stringstream is also useful for handling a line at a time out of a file (or other stream):

Untested, so I apologize in advance if it doesn't compile:

ifstream inf ("someFile.txt");
string line;
while (getline(inf, line)) {
    stringstream ins(line);
    string word;
    while (line >> word) {
        // handle each word on the line
    }
}
raptr_dflo 48 Posting Pro

You're close with

I know a float variable can only hold 7 digits, ...

.
It can only represent about 7 significant decimal digits. Meaning that once you exceed 16,777,216 (just tested it here on my own machine), f++ doesn't do what you expect.

A simple alternative (iterating over integers as suggested by others) is:

int i;
float f, fsum;
for (i = 1, fsum = 0;  i < 100000000; i++) {
    f = i;
    fsum += 1/f;
}

Once you have it working, what can you say about which direction you iterate? Assuming you get different answers, which one is "correct" and why? (Hint: the answer is closely related to why your loop didn't work!)

raptr_dflo 48 Posting Pro

In case your compiler is fussy, try changing line 3 to:

extern "C" {
  int sum(int, int);//to avoid name mangling
}

Are your .cpp and .s files both included as dependencies of your executable?

raptr_dflo 48 Posting Pro

Can you clarify "get no result"? Were you able to build the executable? If so, did you get any error messages when you ran it? If it doesn't print anything to the console (assuming you're running it in a console window), did it occur to you that it might be running correctly?

Start with main() (at line 45 of the first block of code. After it declares a couple of variables, what does it do next? Skip that for a moment, and what does it do next? How is that next thing implemented? Assuming the code actually runs, are you OK to proceed?

raptr_dflo 48 Posting Pro

Meli123,

It sounds like you're panicking! So first of all, don't worry about what seems advanced and what you do and don't understand. Try things that people here have suggested, and see what works and what doesn't. Try to change things, understanding that your program might no longer work, or might no longer even compile. Then change it back. Make the smallest possible changes each time, until you're more comfortable changing more things.

What -have- you learned so far?
For this program, are you expecting the user to enter a number while the program is running? Have you learned how to print messages out to the user, and how to read in input from the user?
Do you know how to write a loop? E.g. "while" or "for"?
Do you understand what people have suggested as far as how to get successive digits from a number?

If you know how to display output to the user, use that to display output for your own use (debugging output): take a working example, and print out messages to yourself as often in the code as you like, to see what it's doing each step of the way. If you still don't understand something specific, please post your own code (copy and paste it into the editor, then select it and click the [ CODE ] icon at the top of the editor -- this will make it look like everyone else's code contributions in this thread), …

raptr_dflo 48 Posting Pro

In your first block of code (reading the logfile), since the date should always be the first thing in a line, you may want to consider looping over getline(logfile, line) instead of over logfile >> next . Within the loop, you can create a stringstream for line, and grab the date out of the beginning of that.

As far as your checkdateformat() function, you are unclear on the purpose and use of isdigit(); use it on a character to determine if the character is one of '0', ..., '9', along with a test for intervening '-' characters at the correct position. Once you're sure the format is valid, you should no longer need to use atoi() to grab integers (unless you want to check that months and days are in allowable ranges). Since you order your years, months and days in correct order by decreasing significance, simply comparing strings is sufficient.

Don't forget to call checkdateformat() as needed from within your other block of code before comparing one date against another.

raptr_dflo 48 Posting Pro

As far as the surface, from the SDL reference for TTF_RenderText_Solid(): "Returns: a pointer to a new SDL_Surface. NULL is returned on errors." This means the function has allocated a new SDL_Surface object to render the text onto, and it is the caller's responsibility (yours, in this case) to free the allocated object when you're done with it. Otherwise you have a memory leak (as the loop allocated more and more of these surfaces without giving them back) and eventually the program crashes.

The "-" thing is a simple subtraction. SDL_GetTicks() probably returns large and relatively meaningless numbers (but a bigger one each time), so what you want instead is how many have gone by since you started. You capture the first value into variable "start", and then later find out how many ticks have gone by by subtracting that first value from the current value returned.

raptr_dflo 48 Posting Pro

I may be mistaken at any point here, so try one thing at a time and see what (if anything helps).

First, at lines 9-12, you can declare your global function-pointers here, but I don't think you can call wglGetProcAddress() (or any other function) in the global scope. I think you need to assign the pointers to NULL and then call wglGetProcAddress() maybe in your GL.Init() or even just in main():

#ifndef GOODGL
if (!glGenBuffersD)
    glGenBuffersD=(PFNGLGENBUFFERSARBPROC)wglGetProcAddress("glGenBuffersARB");
...
#endif

In your destructor in lines 47-54, if you always allocate vars as vars = new glVertexStructure[numv]; then you should always deallocate it via delete [] vars; whether numv is 1 or greater. delete vars; is intended to be used in conjunction with vars = new glVertexStructure;. It might work as-is, but your code is actually cleaner without worrying about the count. Of course, still don't try to delete if numv is 0 (or equivalently if vars is NULL), and don't forget to check whether numv > 0 before allocating in your copy-constructor, assignment-operator, etc.

In lines 111-127, are you really going to support a statement like model = "filename.ext";? If not, you don't need this assignment operator. If you keep it, initialize the 'model' member as well (you set it to zero in the previous method).

In operator+=() (lines 144-156), you don't make your temp[] array any bigger than vars is, and then you assign the new 'add' piece into the wrong array and don't check vars before deleting, so …

raptr_dflo 48 Posting Pro

Not so. If you don't provide a ctor, the compiler is required to create a default one for you.

While that sounds vaguely familiar now that you remind me, how did the OP get the originally reported error?

I am getting an error "undefined reference to 'Item::Item()'

Or is the problem that he got the error when he uncommented the empty implementations in his Item.cpp, without explicitly adding them to his Item.h? While apparently not necessary, I -always- include a constructor (at least one, even if it's empty) and destructor in my classes, so I haven't run into an issue like this. Thanks for the clarification, after 20+ years, I'm always learning something here!

raptr_dflo 48 Posting Pro

For you first example, when you say "it changes back to 0 ( its just a part of the code )", I assume you mean there's additional code you haven't included (but is relevant to the behavior we're discussing) which reads something like:

if ( event.type == SDL_KEYUP )
{
    if ( event.key.keysym.sym == SDLK_UP )
    {
        message = 0;
    }
    ...
}

Also, to clarify, the value doesn't change "while you're holding the key", it changes to Up when you first press the key (which generates a key-down event) and changes back to 0 when you release the key (which generates a key-up event). It doesn't do anything in between the time you press the key and release the key unless you also track key-repeat events (like when you hold down a key in a text-editor and after a short pause it starts repeating).

Then as far as your second example, why would you expect the value of x to go back to zero? Very little happens "automatically" in programming, and if it does, it's for a reason and -should- be well documented (though documentation is often not nearly as clear or as complete as it should be -- that's a different issue). But your variables shouldn't change value out from under you. If you tell x it should now have the value 5, it should keep that value until you tell it you want it to have some other value. You don't do that in your …

raptr_dflo 48 Posting Pro

Looking at line 32 and lines 76-81:

First, at line 32, you're printing a prompt for what your balance will be after the deposit, then when you call the function, at line 78, you prompt for how much to deposit. So your output text will probably be out of proper order.

You also pass in to deposit() the uninitialized variable amount, then read it and use it only within the function -- so instead, make it a local variable of the function and don't pass it at all.

If you think about what has to happen in what order, the rest will fall into place: prompt the user for an amount to deposit, get the amount from the user, update the balance, print the result of the transaction.

Same for withdrawal.

For your transactions() function, I have no idea what you're trying to accomplish there, but again, you're passing in and using an uninitialized variable.

raptr_dflo 48 Posting Pro

No problem. We were all just starting out at one point or another. As long as you can get it working, that's what counts for now. Points for style can wait until style is expected of you. :)

raptr_dflo 48 Posting Pro

As far as the font issue, it doesn't look as though the problem is with loading the font, but what you do with the returned font-handle after that point. I'm also not entirely sure what you mean by "in the Global" ... you can't call functions outside of main() or other functions, so you should be within the scope of -some- function when you call TTF_OpenFont(). And if you've coded your line exactly as you provided it above, then you've also created a local variable at that point, which won't exist in some other function when you try to use it. If this isn't entirely clear, try posting more of your code, and I'll be able to tell exactly what went wrong.

Then, if by "simple console app", you mean something that doesn't use SDL, then you don't have the same event-loop at your disposal, though there are still platform-specific ways to get at the same information (which is what SDL uses internally so that it is portable across multiple operating systems). Otherwise, post the smallest amount of code that demonstrates the problem, and again, we'll be happy to take a look. Unfortunately, despite many years of software development experience, I still can't read your screen from way over here! ;-)

raptr_dflo 48 Posting Pro

In no particular order:

Do not re-declare your member variables inside your constructor (lines 25-30). By specifying the types again, you have instead created local variables which mask your instance-members, and your instance-members are still uninitialized.

With that fixed, your constructor will be correct, but a preferred format is to initialize the members in an initialization-list, as follows:

Bank::Bank():
    badInput(false), nextChar('\0'), currentNumber(0), sum(0),
    firstChar('\0'), lastChar('\0')
{
    // any additional logic, besides initializing members, can go here
    // otherwise, leave it empty: {}
}

You still need int main (int argc, char *argv[]) , that's the only way for command-line arguments to get into your program.

If you have a whole bunch of different command-line arguments, especially optional ones, the code can get big enough that you might want a separate bool handleArgs(int argc, char *argv, Args & a) function which populated the members of an Args struct (note that in C++ a struct is just a class where everything is public by default) as appropriate, and returns true if the arguments were all valid and all required arguments were present, or false otherwise. But for now, handling the command-line in main() is fine.

You were fine up through

char* inputFileName= new char;
 
inputFileName= strstr (argv[1],"=")+ 1;

(though as AncientDragon pointed out, the first line leaks a tiny amount of memory, instead consolidate to char *inputFileName = strstr(argv[1], "=") + 1; )

But then, call a method passing the filename:

if (!bank.ReadFile(inputFileName)) { …
raptr_dflo 48 Posting Pro

If c is not the largest, simply swap it with another element. The following should be sufficient:

// input values a, b, c here

    if (a > c) {
        // a is bigger, so use it for c
        swap(a, c);
    }
    if (b > c) {
        // either way (note: not "else if"), if b is now bigger, use it for c
        swap(b, c);
    }

    // continue with test for right-triangle

I'll leave it to you to write a function called swap() which swaps it's two arguments (in such a way that the values get returned to the main program!), or just replace the function calls with the code to perform the swap.

raptr_dflo 48 Posting Pro

You are providing the filename via the command-line. You can open the file wherever you like, e.g. by passing the filename to a method.

As far as why it doesn't work, you say you can't read in the first character of the file, but there's nothing in the edited-down source you've posted to indicate where you're trying to do that. Let's start at the beginning, and see your declaration for you Bank class. Did you remember to include a default constructor method Bank() and a destructor method ~Bank()?

raptr_dflo 48 Posting Pro

So if level is equal to N already, doesn't it mean compiler will skip the part where function is being called by itself?!

Yes, that's exactly what it's supposed to do. level starts out as zero (well, -1, then immediately increments itself to zero), and by the time it equals N you've finished creating a permutation, so you print the contents of the Value array and return. This is the part about stopping the recursion so it doesn't get stuck in there forever. The else part takes care of what to do when it's not finished yet, including calling itself.

I will agree that this is really ugly code, but if you haven't figured out what it does yet: it puts 1 (level) in each possible position of Value (since they're all zero), then calls Visit(N, k) for each remaining empty position k (where level will then be 2), and so on until it has used all of the valid values of level (the last remaining slot will still be zero, but that's OK, it's a valid value for a slot). If you want to see it working, call print() from a variety of additional places and watch how the values change!

raptr_dflo 48 Posting Pro

Welcome Sappy T,

I don't mean to sound brutal when you're new here, but:
1) The theme of the forums here on DaniWeb is "you do the work, we help you understand the concepts and spot errors in your code." We don't do your work for you.
2) Please don't post in months-old solved threads. Even if you have a question directly related to it, please start a new thread.

Read the "Read this before posting" thread at the top of the Forum list!

That said, since the thread is already solved, and many months ago, I'm going to say "No, read everything in this thread and do it yourself." If you get stuck, please start a new thread, and post your code, and we'll be happy to help you out.

raptr_dflo 48 Posting Pro

If I'm not mis-reading your write-up, the data in the file will all be read into your second array, each element in the array will correspond to one of the gates in the circuit, will have 1 or more inputs and 1 output. (For simulation purposes, you might want to include a fake gate with only an output, user-settable to hi or lo. And don't forget that once you start bundling gates into higher-order sub-circuits such as flip-flops and half-adders, you may also want more than one output, but your file-format doesn't allow for that yet)

Sounds like a data structure to me:

struct Gate {
    std::string gate_type;  // AND/OR/NOT/...
    std::vector<int> inputs;
    int output;  // or std::vector<int> outputs;
};

And then an array of Gate instances:

std::vector<Gate> gate_array;

Since you don't know a priori how many inputs a gate will have (but you can certainly error-check, and should, against the gate-type, a generic input function becomes:

std::ifstream& operator >>(std::ifstream & in, Gate & g)
{
    // get a line and prepare to read from it
    std::string line;
    if (! getline(in, line))
        return in;
    std::stringstream ins(line);

    // read a gate from the line
    ins >> g.gate_type;

    // to put the first N-1 integers into inputs, and the last one into output,
    // we need to know one step ahead of time when we get to the end of the line.
    // note: this will work for the case of no inputs (only an output) as well
    int …
raptr_dflo 48 Posting Pro

You also appear to have an un-matched close-brace near the end of line 878 (I think you meant to provide an open-brace at the beginning of line 877).

raptr_dflo 48 Posting Pro

Glad to hear it. Please mark the thread as "solved" for us. Thanks! :)

raptr_dflo 48 Posting Pro

The original problem is that with the constructor and destructor source missing from the class prototype, and commented out in the implementation, there was no way for your line 10 to work: Item test; . In order for the compiler to create a default instance of your class, there must be a constructor (even if it's empty and doesn't do anything). And there really should be a destructor, even if it doesn't need to destroy anything else for you. (note: "really should" might turn out to be "must" also.)

raptr_dflo 48 Posting Pro

Maybe you should consider naming your variables "initial_balance" (if you need to keep track of that for any reason) and "current_balance". Your current_balance is the value that will keep changing every time you do a deposit or withdrawal.

You don't need a "static number" to keep track of the number of transactions, since you're already using global variables for everything. Call it something useful, like transaction_count, make it a global with all the others, initialize it to 0, and then do something to it (left to your discretion) each time you do -any- transaction. (As written, your "static number" just keeps track of the number of times you've printed out your number of transactions -- not what you intended!)

raptr_dflo 48 Posting Pro

I thought this looked familiar, then when I went and looked it was your thread.

You're not using seekg() correctly. The second parameter is the seek-direction (position really, ios::end in this case), while the first is an offset from that position (in your case 0, or possibly -1, see what works on a file with known content). cplusplus.com is a great reference.

Now think about what your loop needs to do, and the order in which it needs to do it. And what's with the goto statements? You're not programming in BASIC any more.

P.S. Apparently Nathan was answering at the same time I was! :)

raptr_dflo 48 Posting Pro

Try putting the numbers 1-20 into your array first (in order), and then shuffling it. (Hint: start by picking a random element-index and swapping that element with the last element in the array, now you have only 19 more elements to deal with, etc.)

raptr_dflo 48 Posting Pro

But regardless, welcome to the forum, ananyadiwas. And I sincerely hope I haven't scared you off completely!

raptr_dflo 48 Posting Pro

[cout<<] and [cin>>] are keywords since they are built by characters & have special meaning (i.e, these words are reserved for printing and accepting) in the headerfile [iostream]

All keywords and identifiers are "built by characters", so I'm not sure what distinction you're trying to make here.

cout<< is neither an identifier nor a keyword, it is a combination of the identifier cout (referencing an instance of class ostream) and the operator << (a set of functions declared to be friends of class ostream, and defined as ostream & operator<< (ostream & ostr, const Type & val); for various type-values of "Type", and you can also add your own such functions to your own classes as well.

cin, cout, cerr, etc. have "special meaning" only in that they are declared in the iostream header (or possibly the ostream header for cout and cerr, and the istream header for cin) and connected properly to underlying file-handles for your convenience. They are in no way "reserved", and if you do not #include <iostream> in your file, you are free to declare them to be of any other type, and for any other purpose you see fit. Though doing so will likely confuse other programmers. Thus, they are meaningful only by consensus and consistent usage.

raptr_dflo 48 Posting Pro

And romanNumber is declared as int at line 17. Definitely not the case. :)

raptr_dflo 48 Posting Pro

Also, if you haven't discovered it yet, your conversion is broken starting at line 20. Take any starting number, say, 2937, and trace through that block of code by hand, and see what values it's going to get for the four index variables.

raptr_dflo 48 Posting Pro

While WaltP's input is excellent, the actual problem with your playerPick is the absense of braces around the code-block for each choice. Starting at line 53, this should be:

...
    if (playerPick == 1) {
        // indent here!
        ...

and there should be a matching close-brace after line 73. Repeat throughout.

In addition, identical chunks of code are "A Bad Thing". If you realize you need to fix one, then (in your case) you need to fix 9 of them, all the same way, without missing any or accidentally getting one wrong.

Instead, I'd recommend writing simple functions at least for the following:

bool PlayAgain(void);  // prompt the user, get his response, return true or false
bool ShowStats(int wins, int losses, int gamesPlayed);

As WaltP suggested, see how short you can get your outer switch statement without losing any current functionality. Note: anything you do every time, no matter what, can be done after the end of the switch statement, instead of doing it each time it comes up.

As far as the goto statements, yeah, get rid of those. Instead try something like:

bool keepPlaying = true;
while (keepPlaying) {
    // srand() only needs to be called once, so do it before the loop
    // start with the CPU picking its number
    ...

    // any time you have a goto, instead do:
    keepPlaying = false;

    // and then make sure you don't inadvertently execute any code below that point --
    // since you …
raptr_dflo 48 Posting Pro

I bow to Mike's expertise here. My notions of efficiency are based entirely on hearsay, and nearly as old as the first C++ compilers; so if he says exceptions are the way to go, then it may not be "The Truth"(tm), but it's likely a more informed and up-to-date opinion than my own. This old dog (referring to myself) can still learn a new trick or two. Thanks for the insight!

raptr_dflo 48 Posting Pro

Ashok1514,
You may have missed earlier comments to the effect that this forum is not about providing complete solutions. It is up to the original poster to try to learn from help offered, and write his/her own code.

That said, when posting code in the forum, please use [ CODE ] blocks. This numbers the lines, uses a fixed-width font, and maintains indentation, similar to a programming IDE or simple text-editor. The simplest solution is probably to click the [ CODE ] icon at the top of the editor, and then paste your code between [ CODE ] and [ /CODE ].

raptr_dflo 48 Posting Pro

Perhaps the author's intent is: the complexity of finding the node to delete is O(n/m) (on average), but once found, the complexity of deleting that node is O(1)? Since I don't own a copy of the book, and you didn't explicitly quote the author, I can't be sure.

There is a listing of known errata available on his website -- you'll need the edition and printing of your book, and page number of the suspected error, to see if it's already been reported.

raptr_dflo 48 Posting Pro

You're replacing your orig[] values as you iterate across your row. You need two loops here, one which computes your next[] values without corrupting your orig[] values, and then another which copies the all of the next[] values back to orig[].

Once you have your code working, you can have fun making it more efficient. How can you avoid doing the copy at all? (Hint: instead of two separately named 1-D arrays, have a 2-D array with 2 rows in it.) Can you think of a way to have only a single 1-D array? (Hint: as you iterate across a row, what's the farthest-left original value you need to maintain?)

Enjoy!