Jump to content

  • Log In with Google      Sign In   
  • Create Account

stitchs

Member Since 22 Feb 2011
Offline Last Active Oct 21 2014 02:38 PM

Topics I've Started

C# trouble obtaining a decimal value.

04 October 2014 - 09:46 AM

Hi all,

 

I am working through book exercises for C#. And one of the questions is to convert a monetary amount, represented by a double.

 

I have encountered a small error when I try to extract the penny value from this Double value:

 

for example:

 

I input 47.32. I use the formula/code:

int penniesToConvert = (int)((moneyIn - Math.Truncate(moneyIn)) * 100);

This takes the double value, subtracts the Integer part, multiplies by 100 to make .32 into the Integer 32, and casts it to be placed in a new Integer type. This is then used for calculations later.

 

Until now, I assumed this was fine, and it gave me an Integer value of 32. I changed the penny value of the original double to test it; 13, 47, 63 etc.

 

It's only when I input .33, that the Integer I get back is 32. I extracted the part of moneyIn - Math.Trunc... (without multiply by 100) and when I look through the debugger, I get a value of .3299999999... Which, when multiplied and casted, becomes 32. The same happens with the value 66. Why is this, is there anyway to account for these, or is my method of extracting the penny value incorrect here.

 

On a sidenote, this is only in Chapter 2 of the book, so I can't imagine that the solution should be too complicated.

 

Any help on this would be much appreciated.

 

Stitchs.


Returning to Programming

14 June 2014 - 06:19 AM

Hi all,

 

So after a year out from programming, and the forums, I have decided to return to thing that I love!

 

I have been out of the loop for so long that I am effectively starting again. I want to start with a language that is easier to understand, and plug away at, than C++. It didn't work for me before, but I hope to go back to it at a later date.

 

I want to program, and I want to see results fast(er than C++), so I have decided to go with C#. Is this a good choice? What are good resources/books to start from the ground up. Is it worth going into XNA.

 

I know this sounds like a lot to ask, and I am not unfamiliar by any means with forum guidelines, but if there is any advice, I will gladly take it.

 

Thanks in advance for reading/replying,

 

Stitchs.


'Completed' Pong Project; looking for Critique.

29 December 2012 - 09:02 PM

Hey guys,

I have been working on this for about a month and half now, with two weeks spent on the first iteration and the last 3-4 on changes suggested by this wonderful community.

 

I have worked my way through the the list and am now (in loose quotations) finished. I am pleased with what I have learned on the way, and how I will take some of it forward. I also realise that my code was nowhere near what it should have been and have revised much of it.

 

There are still some issues:

  • Hard-coded/cumbersome state machine in Game.h (to be revised in next project)
  • Ball sprite appearing white (this is one I could use some advice on)
  • Game over text being highlighted incorrectly
  • Lack of sound/save functionality.
  • Players should probably by local to Game.h and opposed to Arena.h

 

 

Could I get you guys to try it out, and have a gander at the code as some new feedback would be excellent to take into the next project. Please find this below.

 

I write this late and will probably think of extra things, and add them tomorrow.

 

Regards,

 

Stitchs.


Comparing a negative value against std::vector.size()

15 December 2012 - 04:23 PM

Hello community,

I am having a minor issue in my code, I have replaced an Integer variable with the std::vector.size() in a comparison statement (please see below):

[source lang="cpp"]if(selectedOption_ > (optionsList_.size() - 1)) { selectedOption_ = (optionsList_.size() - 1); } else if(selectedOption_ < firstSelectableOption_) { // Highlighted option does not trigger as going less than 0. selectedOption_ = firstSelectableOption_; }[/source]

Before, I compared SelectedOption to an Integer (numOptions) and this worked as I expected, if it went greater than said number then it would be reset to numOptions, else if it when less than 0(firstSelectableOption), it would be set to zero.

Once I replaced it with size(), if the SelectedOption goes less than zero, it triggers the 'greater-than' clause and sets the SelectedOption equal to whatever the size()-1 is. I have looked through the debugger and the numbers are coming back as expected: SelectedOption becomes -1, and size in this instance being 2. So what is going on here. The quick-fix solution I am using is this:

[source lang="cpp"]if(selectedOption_ < firstSelectableOption_) { // Highlighted option does not trigger as going less than 0. selectedOption_ = firstSelectableOption_; } else if(selectedOption_ > (optionsList_.size() -1)) { selectedOption_ = (optionsList_.size() - 1); }[/source]

This ensures that the check for going less than zero occurs first, which solves the issue I am having, but does not answer the question it puts forward.

In short, is there something I am missing that would be firing the if-else in reverse order. Also, I have checked and am not setting size equal to something different elsewhere.

Thanks in advance for your time,

Regards,

Stitchs.

Pong Project near completion; looking for Critique.

02 December 2012 - 05:17 PM

Hello community,

I have completed a small Pong project, I am quite happy with it and am looking towards the community now that I am at a point to share it. At some points it got me down, as this was my first outing with SFML and there are some aspects that I definitely need to understand better (such as the ordering of event queues and key-presses), but I am happy that i persevered.

I wasn't sure where to put this, it is kind of an announcement, but I am also looking for a code critique and some feedback. Basically, I have gone back to basics and am trying to code a game as quickly as possible, with as few mistakes as possible, but they definitely exists. Currently I am aware that the Paddle and Ball classes share some methods, and this will lead me to developing an inheritance structure, this is one of the known issues and an example of what I am aware of in my code.

I am trying to find as many shortfalls and understand why some concepts shine, through the experience of not using them.

A few things I am aware of:
  • Hard-coded values,
  • Movement that jutters at times.
  • Over-diluted with methods that could be combined.
  • Unclear comments in some places.
  • A few methods that are not used or have no body.

I appreciate any feedback on my code and the application itself, and look forward to your comments. Below you will find two rar files attached, one with the exe and one with the Header/CPP files.

Regards,

Stitchs.

PARTNERS