If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

if the result of the first if fails - is false - then the number must be outside the range ie is not between 1 and 100 so the second if is not needed in this case as it is always true. So this could be written

The code doesn't assign Ace, King etc. It creates an array of strings with the individual elements being the strings "Ace", "King" etc. The same with the suits. The individual elements of these arrays can then be accessed by specifying which element is required starting from 0. So "Ace" is element 0, "Two" is element 1 etc.

% is the integer modulo operator. It returns the remainder of the the two numbers. So 7 % 3 is 1 as when 7 is divided by 3 the answer is 2 remainder 1. 8 % 5 is 3 as 8 divided by 5 is 1 remainder 3. The result is always a number beween 0 and 1 less than the second number. For 8 % 5 this would be 4, for 7 % 3 this would be 2.

So for the card values, we want a number between 0 and 12 inclusive which is used as the index to the array. The first suite is the input range 1 to 13, the second is 14 to 26 etc. So first subtract 1 to get in range 0 to 51. Then the result of the modulo 13 operator is a number in the range 0 to 12 which indexes the value array to get the card value.

For the suits, again we want an index number in the range 0 to 3 inclusive. In this case we use integer division. So 7 / 3 is 2, 8 / 5 is 1 etc. Using the range 0 to 51 and dividing by 13 this gives a number in the required range as 0 / 13 is 0 and 51 / 13 is 3.

And thanks for the info 2k! You guys have been awesome! I'll have to re-read some of that, but I get the gist of it. but again, thank you guys for shooting straight with me and leading me to how to learn this better

please also tell me how to compile and run a program in Dev c++ latest version.usual methods dont work.but when i hit open and run it opens an open dialog box.it should compile the program shouldnt it.Devc++ 5.4.0
Regards.

ok, something that i cant wrap my head around are identifiers like char, int, double, float....etc etc. I cant consistently understand which one to use except for 'char', which is like a single character like 'm'. And I've been guessing most of the time when I've tried to use 'int' or 'double'. I know I'm supposed to use it based on the range, but I dont grasp how that works. This is one of the things i either try to figure out with trial and error. and as stated here before, i cant learn to do this like that. ive read through my book, Ive read this page (http://www.cplusplus.com/doc/tutorial/variables/).

so if i want to create an identifier for 'phoenix', how exactly do i determine if it's 'int', 'double', or what?

btw, i dont have any projects this week. Im just doing some extra work to correct the way ive been building codes

int is used when you want to store integers (whole numbers with no decimal part) eg 2, -4, 456 etc.

double is used when you want to use numbers with a decimal part eg 3.456, 4.78, -2.45 etc

char is used when you want to use a single character eg 'M', 'T', 'a' etc.

so we can do

Code:

int a;
double b;
char c;
a = 2; //a is defined to be an integer so assigning 2 is OK
b = 4.546; //b is defined to be a double so can hold numbers with a decimal part
c = 'j'; //c is defined to be a char so can hold 1 character

There are variations on these (like signed, unsigned, long etc) as you can see from the article but ignore these for the moment until you have mastered the basics.

The next issue is with strings. A c-style string is an array of characters terminated by the NULL character (NULL or \0). For the moment, though, I'd pass on this until you understand the others.

A string literal are characters delimited by ". So "qwerty" is a string literal and so is "string literal".

c++ also has what's called the string class. This is much easier to use than c-style strings and should be used where possible for strings. "phoenix" is a string literal so needs to be assigned to a string variable.

The type of variable you use depends upon what you want it to hold. Once you know for what you are going to use the variable, the type can then be chosen to match (ie int, double, char or string). Once you are comfortable with choosing and using these then you can start looking at the variations and c-style strings (which can cause problems if not used carefully).

Hope this helps. Ask if you don't understand this because this is fundamental to c++ programming and until you do you'll have problems trying to go further.

Pleased to be of help. If (when!) you have further questions, perhaps you could start a new thread as this one is now getting very long and what it's covering now is far from the original thread question.

If you want some extra simple programming practice, you might want to have a go at these:

1) Your uncle owns several convenience stores in New England and Canada. He originally prices all of the produce sold in his stores in terms of US pennies per pound. In an effort to maintain uniform pricing of the produce for all of the stores, he must translate prices of produce in US pennies per pound to Canadian dollars per kilogram. Your Uncle assumes the exchange rate of US dollars to Canadian dollars is US$ 1 = C$1.26. You have offered to solve this problem for him. The program needs to be user friendly, prompting for input and producing nicely formatted output.

2) A furniture store has just lost the records of the wholesale prices it paid for certain items that it recently sold. However, it still has the records of how much customers paid for these items. The ticket price of an item is always 40% above the wholesale price, and 6.5% retail sale tax is levied on each item. Design and implement a solution to the problem of determining wholesale prices of items from the amounts of money customers paid to purchase the items. The program needs to be user friendly, prompting for input as required including the customer name and item name. The output should be nicely formatted for ease of understanding.

probably a good idea. I didn't want to flood the first page with a bunch of noob questions. I wish i could install the compiler here at work, but they wont let me. So I'll do these this weekend. I may type them out in notepad or something here at work, but that's as much as i can do at work But I think i will post the codes for these 2 practice programs on this thread, but any further questions on other stuff, ill go ahead and create a new one.

I like this forum! You guys have been a great help! Hopefully one day, I can be as helpful to others!

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.