Sign in to follow this  

text based application

Recommended Posts

well since I suck at game programming I would like to some text based c++ programming. I have built a very simple calculator application using classes and objects. since I am brushing up on my c++ programming skills, what is a good web site(s) where I can get better at my c++ skills. if you have any ideas where do I go further I would appreciate that as well.

Share this post


Link to post
Share on other sites

what is a good web site(s) where I can get better at my c++ skills. if you have any ideas where do I go further I would appreciate that as well

I am pretty sure that if you put your key words for the questions in google search engine, you would come up with more than enough results

And this would be better for you as you would be able to have a glimpse at each c++ practice tutorial, test them and see which ones suit you the most. Rather than some else who doesn't your most comfortable learning style decide for you 

Share this post


Link to post
Share on other sites

well I am working on a c++ tutorial, I have a very simple question.in the following code I am doing the following.

1) I am putting a j value in temp variable

2) I am adding one to the j value

3) I want to put the temp value in the j value plus one.

this is a very simple swap routine.

here is my code

temp_one = j;

j=j+1;

[j+1]=temp_one;

I am getting an error in the "[j+1]" part of my code.

I just need a second set of eyes to solve this problem.

Share this post


Link to post
Share on other sites

All these years, and you still don't understand how to ask questions properly. Your posts are honestly fascinating, but not for any good reason.

Your "code" (which is not copied directly, so errors could potentially be hiding in your actual code) seems to doing exactly what you said it should do in the steps above. If that makes sense or not is impossible to tell (although it's sane to guess it doesn't make sense). Your steps do not describe a swap routine, though.

And you say you have errors, but you do not state what the errors are (copied directly, not paraphrased).

Apart from that, if you are still dead-set on learning, keep looking at the tutorial and trying to understand what's going on. Don't just blindly type in letters and hope for the best. Read about thing, understand what you're supposed to do to implement thing, write code to implement thing -- DEBUG code it thing is not correctly implemented.

Share this post


Link to post
Share on other sites

The problem is that what you think it should do, is not what you actually told the computer to do. To get forward to wards solving your problem, you have to understand that "what it should do" and "what you told it to do" are two different things.

Your aim is to align these two concepts, that is "what you told it to do" results exactly in "what it should do". Obviously, you haven't reached that point here.

 

To get forward, you have to let go of the former, and only consider "what you told it to do". The simplest approach to that is to play "dumb computer" for a while. Nothing else but the actual code exists in the world. Your programmer told you to compute it, and you always do what your programmer says! No idea what it means or does, but my programmer does!

Take a piece of paper and a pen, and write down the value of all variables. "execute" one statement at a time by manual computation. Write down the statement that you're going to 'execute' below the variable values. Compute the value to assign, and "assign" it by writing the value of all variables again, where the assigned variable gets changed.

Yep it's slow and dumb, but it works.

 

 

In time, you'll get better at it, and eventually you can do this without ever writing anything down. This is what experienced programmers do in their head when "reading code". They look at the computations, and deduce how variables change.

 

Once you did the above, you now have A) your steps as you think they should work, and B) the actual code steps that the computer performed.

Now it is time to map A to B. If all is well, some of the first statements of B belong to the first step of A, then, some of the statements that follow belong to the 2nd step of A, and so on. Decide for each statement that you "executed" while playing "dumb computer" what step it belongs to. Then, take the start and end of each A step, and compare the values of the variables at the start with the values of the variables at the end. Are they correct for implementing that A step? If so, continue. If not, then obviously something is wrong in the code, as you apparently told the computer something else than what you intended. In that case, look at each statement from B carefully, where did it make a wrong computation? Once you found that, you can fix it, and play the whole game again, hopefully with a better aligned "what I think it should do" and "what I told it".

For some practice, and insight in your current problem try

int a = 1;
int b = 2;
a = b;
b = 3;
b = a;

and one step further:

int a = 1;
int b = 2;
a = b;
b = b + 1;
b = a;

which looks a lot like

int temp_one = 1;
int j = 2;
temp_one = j;
j = j + 1;
j = temp_one;

Does it implement your steps?

Edited by Alberth

Share this post


Link to post
Share on other sites
The overall program is probably short? If so - why not post it all?

Sometimes compilers don't mark the logical point in the source code where a human would agree the error is - for various reasons (implementing a compiler is a fascinating project) some types of mistakes make the compiler see the code very differently than a human would.

You should post the exact error messages you are seeing, including line numbers.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this