jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

but when i changed 'void' with 'int' I got the same result..! sorry I have two questions:
1) what is the difference between 'void main()' and' int main()' ?
2) if I become professional in c++ in the future, is it enough and I will not need java and c#?

Great! I'm glad you got it working.

For the answer to #1, see http://www.eskimo.com/~scs/readings/voidmain.960823.html. When the operating system (or other code) that's calling your program expects to get an integer value back from your program and you don't give it one, it can cause problems.
At times these return values are codes to let the calling program know whether your code has exited successfully (which is represented by return 0; )or if another error has occurred.
If you declare main as an int, even if you don't put a return 0 (or other return value at the end) it will implicitly return 0 to the OS anyway.
You may not have experienced any change or error in switching from void to int, but you've prevented the possibility of things getting fouled up when running the code under different conditions.
I'm probably leaving off some bits and pieces of the details here but if you google void main versus int main lots of stuff comes up.

As for #2 I'm not really sure, but I am sure that the requirements for programmers vary greatly from workplace to workplace and region to …

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Ok, good that's a bit closer. I told you about line 7. Putting the semicolon after the for() will cause the loop to be skipped. Get rid of it.

Also, I didn't mention it before but main should always return int. void main() is not standard and should be avoided.

After you fix the semicolon, one more problem is going to crop up. See if you can figure out how to rearrange things to prevent this.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Dude, you've got to listen to what people are trying to tell you and not just repeat your question. If there's something you don't understand, say so.

Look at the structure of your for loop. Compare it to other for loops you've seen. How many have had a ; directly after the for statement?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your equations just a little off. First you should convert the angle from radian to degree, then apply the equation given. Good luck with the Physics, I loved that class.

radianAngle = degAngle * PI / 180;
A = g*sin(radianAngle);

He did have the conversion in there on line 11 within the sine.

OP, that does correct the A value for you, but it's up to you to wrap it all into a function (according to the problem description). Did you look up any information on how to do that?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Hi,

my code:

#include <iostream>
#include <iomanip>
#include <conio.h>  //leave this out, it's nonstandard
using namespace std;

void main()
{	int i=32;
	for(i=32; i<=256; i++);    //something extra on this line
	cout << setw(0) << "value" << setw(14) << "character" << endl;
	cout << setw(0) << i << setw(10) << static_cast<char>(i) << endl;
	getch(); //change this to cin.get()  it's much more portable
}

my output:

You need to shift your for loop around (first remove something that doesn't belong) as you only want to print out the numbers that many times -- the way you have it once you remove the extra something from that line you would print the header that many times. Take another crack at it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Hint: use the method String.IsNullOrEmpty()

You may want to change around your for loop into a while or do/while loop. You could use either of those structures to make sure you have at least 1 item in each and keep re-prompting if you don't.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Everywhere you were accessing ".number" use your getter (like in lines 154 and 164). I don't know that you need the friend class bit up in the card class if you use the getter. Debugging the game itself is going to take time and making sure things are getting where they need to go. Start putting some cout statements around critical parts so you can see what the values are (like the cards you drew and the value of each, etc).

kvprajapati commented: Great! We appreciate your help. +9
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I meant more like:

int getValue() { return number;}

(no implementation is needed)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Nothing even that fancy. It'll go around line 30 or so (within your card class declaration). One will have the return type int and take no arguments (then put the braces and the return right after it) and the other will return Suit (and be similar to the first one).
Then once you have a card, just use the .getValue() method you just implemented (or whatever you will call it) to get the value of the card.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Don't start a new thread I just replied to your other one...

n doesn't exist in your class, you need the number value, see next sentence.

Make a getter method for your card class that returns the value. Make a second method that returns the suit if there is a tie.
(these are 1 line methods so don't sweat them, just return the card value (or the suit in the second case)).

Don't pass deck into shuffle.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Don't give shuffle any arguments it knows the deck it's shuffling already

Make a quick "getter" for card that returns the card value

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You know what a function is, right? (I think you've posted stuff before with them). There's no function (besides main()) in your program. Read up on them and try again with it. The calculation for A is incorrect, you shouldn't need any programming for that.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Perhaps my level of sarcasm wasn't adequately represented in my reply. :)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

in
main(); or card if not in game

Good way to hedge your bets there ;) Still belongs in game, but remember anything you declare (when not allocating memory) in a method gets destroyed when the method terminates. Where do member variables belong? It's a member variable of your class game.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See if you can figure out what the error message means on your own. Hint: rework your main so that returning from that function you'd be exiting the program. Another hint: When do void methods return? Exploit this to let everything finish up when you press n and just respond to the Y prompt.

A sneak preview: figure out where your deck array really belongs...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm not sure you need line 94 for anything. If you really need numbers for the players make those separate. I think you were passing those numbers into 140 and 141 when they are really not necessary, since your card object should call display on itself rather than having anything to do with the players (so as in npc.display() -- without the cout since your method returns void). for (p == n ) EDIT: I think you meant if. But what if the n and p come up the same again? Use a loop.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The key part of the assignment was make a function. You have thrown all of your code into main(). Make it a separate function that you can call in main().

Double check your formula for A with a calculator. Also, you did not use the M_PI constant, you wrote your own (which is probably nearly as good, but it's not what the exercise asked for).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're not understanding my point. The way you pick numbers is fine (that text example is just getting the elements in the array by dividing the total size by the first element). Your player and npc need to be of type card.

card player;
card npc;

then the types match up perfectly. I'm not sure how the int crept into things... lol.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
[I][B]int[/B][/I] player; //player's [B][I][U]card[/U][/I][/B]
int npc; // computer's card

and what is the datatype of deck[p]? (the compiler is giving you a hint)
See post #12 again.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I was able to get something like this to work:

string value = "a, ,b,-,c,d";
string[] text = value.Split(',');
//change it to a list
List<string> texlist = text.ToList();
texlist.RemoveAt(i);  //use a loop and the RemoveAt() method

I couldn't find a way to do it on the array directly but there may be a means to do it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No biggie, it happens to everybody.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Congratulations on (re)discovering the Cantor set. Can you supply a formal proof?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

40 hours 20mins and 10 seconds in angle?

There's no such thing. Hours are not a measure of an angle. It so happens in this example that the OP posted you can find a relationship between the length of the hands on the clock, the angle between them, but this is merely artificial and has no bearing on the time.

Take another look at it. Angles are measured in degrees, minutes, seconds. These are unrelated to hours, minutes, seconds. The degree is divided up into 60 parts which is why they happen to call it a "minute."

See also: http://en.wikipedia.org/wiki/Minute_of_arc

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to take a quick look through your text in terms of declaring objects of a class. Unless display is a static method you can't say card::display(). Your main is going to be off too. You need an instance of game (e.g., game mygame; . Your game instance won't know about the deck as it is. I would make an instance of deck within game. That way the members of game can access it directly.

There's more confusion with your draw method. You are passing an integer to it that never gets used. In addition you still have cards as an int value. A card is of type card. Ideally you could also have a player class which holds one card but for now just draw off a card for each player to hold, then compare them.

I'll have to read the spec again, but as far as I can tell you can just shuffle the deck in between turns and start fresh.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Ah I see.... this way it is less likely to have the same card chosen by the randomizer. this is what I use to ready the rand()

#include <process.h>
#include<ctime>


int main()
      {

       srand(time(NULL)+_getpid()); // I was told that using the pid of the computer would give me better results.
       //etc code.
       }

but alas the time+pid still didn't give me a very random num then. but my instructor told me that it should be initialized in main() not my function (last assignment), because it kept resetting the randomizer. Made my craps game not so random.... it was funny because iSum=idie1+1die2.... the dice would be random, but the total would repeat like it was factoring the total... strange...
I noticed while I researched that classes get encapsulated as defined headers.... so does that mean, that the class can actually initiate the randomized code in a class function, called only once by the main()would still work, because the examples I found did it, or would it not be a good idea? (in a professional POV?)

srand needs only to be called once. I suppose you could call it in the constructor of your class if you were getting random numbers in one of the methods. It's safe to do it at the top of main since nothing will be instantiated or called before then. I'm not completely sure what your average coding practice document would say on the subject. I've never done that thing with the pid. My guess is it …

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

thanks I keep forgetting computers start with 0 when I comment
so just defining....

playercard=deck[r];

....will just choose 1 random number from deck[j] or creates a new deck with an array [j]?

That's just going to get you the one card after you've called r = rand() etc. This assumes you already have the deck within whatever object you've constructed. You'll only want to make a new deck in between "rounds." For the second draw, act as though the first player kept the card.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

this might seem strange to ask
but I never made anything get a random index out of an array
would it look like

int r = rand()%52;// assigning a # (1-52) and storing it

now how to retrieve that random index from the array?

You've got the right statement but your comment is incorrect. It will give you a value from 0 to 51 which is what you want.

playercard = deck[j].  //something to do with 'r'?????????

deck[r] will work.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See my edit above. It doesn't say you can't have a deck class, it just says you must have a card and a game class.

Forget about getting deck to work in card. Deck should be it's own entity. Card doesn't know deck even exists and it should stay that way. Even if you think it should not have it's own class, at least make it an entity in the game class.

EDIT: Think of it this way: If you're going to design a new game, you should be able to take your card class and reuse it. You can reuse your deck too (or retool a new deck with a different number of cards for a different game).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Thanks for elaborating on your question. You need to step back from this and consider the design aspects. Deck should contain an array of card objects. In the constructor for deck you can simply use a loop to deal the cards into your deck (since you are going to shuffle them anyway).

Then there is the issue about passing the player's/npc's card object values from the card class to the deck class... and if we could move the deck::shuffle() to card, it would be better... but i couldn't figure out how to get the array values of "card deck[j]" build within the card class, only main and in my new deck class.

I think you're going in circles a bit. You should leave the deck as a class and create a new one called game (which is called for in the spec). See if you can map out the members of the game class (hint, you'll need a deck and two players).

In main you should instantiate just the game object. You can't use the :: in this case because your methods aren't static.

Take another crack at it and get little pieces of it working first. Then come back and post what you have finished at that point.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Add the directory that the lib is in under Project, Properties, Configuration Properties, Linker, Additional Library Directories and add the name of the lib into Project, Properties, Configuration Properties, Linker, Input, Additional Dependencies.

When debugging you may have to set the Project, Properties, Configuration Properties, Debugging, Working Directory to the directory that contains the dll files.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try something like this:

string concat="";
foreach (Control ct in Controls)
   if (ct is TextBox)
        concat = (ct as TextBox).Text + "\r\n"+concat;
//this puts a CRLF in between each YMMV

(It seems that the foreach is iterating through the controls backwards -- I double checked that they were added in the .designer file in the right order so there must be some reason for it -- so I just adjusted the concatenation order)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I think you need a slight redesign. Perhaps I'm misunderstanding your intentions but you are making an array of 20 strings but each entry will take up 6 of those strings. You'll only have 3 records. I would make a list of string arrays that are each 6 elements long. Then it's just a matter of matching up the index in the list box with the index of the list and assigning the elements to the appropriate TextBox.Text. So figure out how you'd like to store your information (there are other options beyond the one I suggested of course) and post back with your code.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Have you named your executable the same name as some other system software? It doesn't seem like your code has any error message like that. Try renaming your program.

Nick Evan commented: problem solved. +12
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Do you have the AcceptsTab property of the textbox set to true?

I was able to get it using

private: System::Void textBox1_KeyDown(System::Object^  sender, System::Windows::Forms::KeyEventArgs^  e) {
	if(e->KeyCode == Keys::Tab)
		 MessageBox::Show("Tabbed!");
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I think this program is really easy, I tell you why:

When the user inputs the data forexample hours , minutes and seconds. It is possible to convert that into angles. On calculators there is special button to do that as well. You can check this link below and that should be it :]
http://id.mind.net/~zona/mmts/trigonometryRealms/degMinSec/degMinSec.htm

FWIW, that's not correct. You can have a bearing for a ship in degrees/minutes/seconds and it has nothing to do with time or the clock. Minutes are a division of degrees and seconds are divisions of a minute. See this which also calls them arcminutes and arcseconds.

(Pardon the off topic post and I know this thread is getting a little stale. Sometimes you can get good baked goods on the day old shelf in the grocery store though)

jephthah commented: i like the day old donuts, myself. +7
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

On line 31 you are trying to pass "cout" instead of "count" to your method.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

How about "Oh, what a Daniweb we weave when first we practice to inform" (*as he ducks the thrown tomatoes).

or "Do IT on our site"

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Where do you actually open outfile? Make sure it's open before you start to write to it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This is just the beginning of my name sort prog... I am starting with just reading in the names and then outputting each name... As of right now, it is crashing after displaying the first name... I think it's something with my array.. rectangular, instead of square, but don't know what to change...???

My comments are inline

#include <iostream>

using namespace std;

char **Create2DArray (unsigned int NumRows, unsigned int NumCols)
{
	char **	TwoDArray;
	TwoDArray = new char * [NumRows];
	for (unsigned int i = 0; i < NumRows; i++)
		TwoDArray [i] = new char [NumCols];	
                    //                       ^^^^^
        return TwoDArray;
}
//You are correct in allocating the 2D array by rows here.  
//Each of your rows should have [U]NumCols[/U] as a length

//FreeArray should take NumRows otherwise you're trying to delete
//20 things when you may have far less
void Free2DArray (char **TwoDArray, unsigned int NumRows)
                                              //   ^^^^^^
{
	for (int i = 0; i < NumRows; i++) //should probably be unsigned
	            //         ^^^^^
                  delete [] TwoDArray [i];	
	delete [] TwoDArray;		
}

//... down in main()
	
     cout << "You have entered: " << *TwoDArray << endl;
//This is not correct.  Make a loop and cout them by TwoDArray[i].

Also, you should look into using cin.getline() instead of the >> operator that way you can have names with spaces.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes but mathematically that is the equivalent of calculating the numerators of both fractions if they expressed with a denominator of (denominator 1 x denominator 2) my statement holds under the implied assumption (or at least I implied it given normal fraction mathematics) that given any number of fractions you can always find a common denominator which they can all be expressed in.

Yeah, I get what you are saying. It makes sense. "Cannot compare fractions...same denominator" was the phrase that had thrown me in what you said. I would consider the cross multiplying to be a possible "comparison," is all. If I had read your post a second time before I posted I would have gotten what you were implying in the purest sense. Anyway, no big deal.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can not compare fractions unless they have the same denominator. If they have the same denominator then you can simply compare the numerators.

If they don't have the same denominator you can multiply denominator of the 2nd by numerator of the 1st and then denominator of the 1st by numerator of the 2nd. If denominator 2 times numerator 1 is larger than denominator 1 times numerator 2, then fraction 1 is the bigger of the two. A diagram:

(N1*D2)     (N2*D1) 
N1                N2
__         X      __             if  N1*D2 < N2*D1 => Frac1 < Frac2

D1                D2
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can concatenate the variables right onto a string:

double pi = 3.14159;
int i = 3;
MessageBox::Show(pi+" rounded down to the nearest integer is "+i);

If the object is not of one of the fundamental datatypes (int, double, etc) you will need to call it's ToString() method. The fundamental types have their own ToString() method but it's called implicitly (I believe) when you concatenate a number.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The OP is only using it as a loop variable in Graph. I don't think there's a need to declare it all over the place. In object it's just a "dummy" parameter variable so it's not necessary there either.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You ought to be able to use a picturebox, the contents of which you can probably get as a stream from the web, go from a stream to an image. Were you planning on writing the text onto the banner directly? If so you could have a label that you align over the picturebox. I realize I'm being a bit vague but I'm not absolutely sure what the requirements are.

I did find this page which has an example in C# that I was able to put into C++/CLI using dynamic_cast instead of the c style casts.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Look at line 94: for ( ndeps=0; fin >> buffer && buffer[0] != '-'; ndeps++); There's one thing that's missing there and one thing that's extra. You need to declare ndeps as an int (since the other ndeps in the program is unrelated making the global variable is definitely not a good idea) either within the loop body or before the first for loop -- beforehand for sure if you want to use it for both loops in that method.

More importantly, this for loop won't even execute because of the extra semicolon.

There are some scoping issues (with deps) that come up after you resolve all this but see if you can figure it out.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

pi / 180 is what you'd use if you were making the conversion from degrees. i don't think he is doing that, his input is just in radians, actually the input is the multiplier, like 1/4 * PI or 2 * PI, etc.

I didn't read the OP's prompts, so that's my bad.

@OP: To illustrate the problem of approximations that jephthah was explaining look at this graph of sin x versus it's series approximation http://en.wikipedia.org/wiki/File:Taylorsine.svg. It only holds over a limited interval. I think you can in fact improve this a bit by specifying a point about which you are approximating the function (see http://en.wikipedia.org/wiki/Taylor_series#Definition where they have the (x-a) instead of x) but there's only so much you can do.

jephthah commented: good explanation +7
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Embaressingly simple!

Thanks again.

Nah, they're just new for a lot of people. They play very well with interfaces if you go down that road at a later time.

Never a problem.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yep, you can shift to using "is"

foreach(BaseGameEntity bge in entityList)
    if(entity is Drop)
       //process it
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Change your constructor
private Dictionary<char, int> alphabetList = new Dictionary<char,int>();
into
private Dictionary<int, char> alphabetList = new Dictionary<int,char>();
Because a Dictionary constructor first has a Key type and then a value type.

I think the OP wants it like he has it because he wants to keep counts of letters like how many times does 'A' show up in a document... (I know this from another thread, I'm not psychic hehe)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use the "as" keyword to cast them (I ignored the list portion for simplicity):

BaseGameEntity bge = new Drop();
(bge as Drop).DropMethod();

or you can use the old fashioned

((Drop) bge).DropMethod();