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

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

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

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

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

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();
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Make sure it's between 0 and 9 and then add '0' to it. char a; a= '0' + 1 (a = '1')

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes, there is an overload which takes a char.

A good reference:http://www.cplusplus.com/reference/string/string/find/

EDIT: AD's got it ^^^^^^^^^ (but that site is still a good reference)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The best thing to do is go through and check all of your braces again, even if you don't think that's what it is. Go to the Tools menu/Options/Text Editor and turn on "Automatic Delimiter Highlighting". After that go to the end of your file and clear out all the closing } and put them back in one by one and you should get the highlight when they match an opening one up above.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No prob. It wasn't evident outright. I had to step through it a few times dumping the dictionary as I went along.

diff eq at the same time

Fun is...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It did remove station 3. Print out the key value pairs in the dictionary before and after. What happened is you delete the id but you never change the station.Next value for Park Place so that when you are stepping through your list you set station = station.Next and print it even though it doesn't exist anymore.
They are not in the right order because the dictionary holds them in the order it added them. Go through in order by index and see if the index exists and if so print it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No, getche() and getch() work the same way. Hit a key and the program continues. You won't get a chance to hit the ENTER.

Sorry, when I wrote "enter" on line 3, I meant the stray newline in the stream from line 1. I may still missing something obvious, it's not intentional I promise.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It would be lines 20 and 21 there giving me trouble now.

It's line 18. Look at what you are comparing.

(stationDictionary[startID] = resolves to string) != (currentStation = int)

lines 63 and 64 of the code before are giving me a null reference exception

Check over lines 61 and 62 again. Make sure there are no marked errors or warnings in your program before you try it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I didn't go over your code in great detail. I was able to run it with the following output:

There is no element at the given ID.
The ID of the station being added already exists.
Name: Boardwalk, ID number: 1
Name: Boardwalk, ID number: 6
Name: New York Ave., ID number: 3
Name: Marvin Gardens, ID number: 2
There is no element at the given ID.
Name: Boardwalk, ID number: 1
Name: Boardwalk, ID number: 6
Name: New York Ave., ID number: 3
Name: Marvin Gardens, ID number: 2

I think (unless I am confused by the usage) you are using a roundabout and incorrect method of accessing the dictionary. I know you had another thread about this but it doesn't look like you were able to change it. I'll give you a couple of lines and you can fix the rest in turn.
Since your id is an integer you can use the [] notation to access elements at a particular integer key:
(from lines 61 and 62 of the second file)

insert.Next = stationDictionary[id].Next;
//since stationDictionary[key] give you Value for that key
insert.Previous = stationDictionary[id];

Also, when you are using the automatic properties you don't need to have an explicitly defined private variable to hold the data-- so you don't need lines 13 and 14 of the first file.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Here was my interpretation (I reserve the right to be wrong, so I'm just seeking for my own clarification here, so I'll beg the OPs pardon)

ans=getche(); //user inputs 'g' <enter> (only room for g in the 'ans')
if(ans!='n'||ans!='y')   //this is true
        ans=getch(); //I was saying enter gets picked up by this
                //apparently that's not the case?

On a peripheral matter, I thought this was funny (from the conio.h of a recent mingw):

/*
 * conio.h
 * This file has no copyright assigned and is placed in the Public Domain.
 * This file is a part of the mingw-runtime package.
 * No warranty is given; refer to the file DISCLAIMER within the package.
 *
 * Low level console I/O functions. Pretty please try to use the ANSI
 * standard ones if you are writing new code.
 *
 */

(my color emphasis added)
You can't make this stuff up...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Put in a cin.ignore() after the ans = getche(); line. The newline ('\n') from the when you entered y or n the first time was staying in the input stream and getting picked up by the getch() which took it as input and moved on. I don't know offhand if the cin.ignore() plays nice with the conio functions.

That being said, I would avoid the conio.h functions unless it's absolutely necessary to do so. Use cin.get() or getchar() (getchar requires <cstdio>) for portability.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Take it into a string and parse everything (either with your own function that multiplies out the place values or something like atoi) up to the slash as one integer and parse everything after as a second integer.

Or a simple way to do it would be have the user input the numerator, print out a slash and have them put in the denominator.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Disp and input should just take plain ol' strings. I'm not sure what you are trying to do with the [ ] but I don't believe it's correct. In the case on the last 2 lines you'll have to use something like sprintf to make a string out of the numerical values and the text and then display that string. I don't have a copy of Matlab to test it on but that's my recollection for the disp and input part.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yep. Reported and noted as possibly a new record for bumping (I think there was one from 2003 a couple months back). It must take a lot of effort to find that post and post on it rather than starting a new one. I'll never understand the motivation....

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Here's an example that gives you something tangible when you click the button. Set the "Tag" property of each of the textboxes to "Text" (or some other moniker).

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
	for(int i = 0;i<Controls->Count;i++)
		if(Controls[i]->Tag=="Text")	 
		{
	  	  dynamic_cast<TextBox^>(Controls[i])->Multiline = true;
		   dynamic_cast<TextBox^>(Controls[i])->Height = 5;
		}
}
tonymuilenburg commented: Wow, your post really saved me time and frustration! :) +0
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

SelectionStart is a property specific to TextBox. Text is a property that all Controls have. To access that property you need to downcast the controls to their particular type using a dynamic_cast to TextBox^ type. You'll have to do some checking to make sure that you have the right controls on your form, perhaps by tagging your textboxes and using that as a criterion to cast them.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Do those functions take any arguments? No. So don't add in arguments where they are not necessary.

You're calling a function, you must use the (). So InterestDue should be InterestDue() just as if you had invoked it anywhere else.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Lines 15-31 in your code above would be what I would call pseudocode. If you're having issues with your code not compiling it's best not to add in more lines that it's going to reject, is all.

Regarding the snippet you just posted. InterestDue, TotalAmountDue, and Payment are all functions. You know how to call a function, you've called one on line 73 (and many others) in the code you posted before. If these functions are to return the values they promised and then send them along into the output stream they need to be invoked properly. Hint: just add ().

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Excellent with the code tags. The rest of it, I'm not sure what you did. You seem to have tossed in some pseudocode ("end if"??) up at the top. You corrected what is now on line 55, which was good, but you haven't corrected anything in your Account::output method. What kinds of errors are you getting now (besides the treasure trove from putting that p-code there)?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Code tags: it's simple. Type:

[code]

//paste your code in here Type:

[/code]
(or highlight your entire code and click on the [code] button on the editor toolbar.

Now, there's a simple error hampering your progress here:

void open_input(ifstream& input, char name[])[COLOR="Red"][B];[/B][/COLOR]

(that would have been on line 37 had you put code tags)
Again you're still missing a semicolon here as you were told in the other thread. Always start with the first error, correct it and some of the others will fall away as a result.

There are still problems with your output method. What are InterestDue,TotalAmountDue and Payment? How would we normally call (invoke) such things?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

i think it has to do with pointers and memory location
but i don't know exactly what to change to make it work

It actually has to do with the fact that scanf uses a space as an input delimiter (so once it hits a space it stops) and the rest of what you typed stays in the input stream and gets collected by the next scanf.
fgets works very nicely to get a full line of input.
Use the syntax fgets(Videos[i].title,sizeof(Videos[i].title),stdin); . The function will put a '\0' at the end for you so that will only leave you with 19 characters to play with. fgets will take in the '\n' at the end of a line so you can step through the string and replace '\n' with a '\0'

other question: how do I return to main from the functions?
I mean , i want to finish my work (adding, modifying,deleting,listing)
then return the value to main and go there and when i want to list
the movies I want to see the latest modifications.

Wrap from lines 28 to 48 in a do/while loop while n !=0. This way when your functions return to main() it'll be primed for another time through the menu. When the flow of the program reaches the end of a void function the flow returns to the calling function (same as it would if your function returned a value and the flow hit a return …

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In the future please try to refrain from giving away a code sample that an OP can turn around and hand in for a grade (as I'm doubtful that not having exceptions and type safety will hinder that). Guide the poster through the process and help him/her reach the conclusions that they need to.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Without something to go on I don't know where your difficulties are. Can you write a program to read a data file? Can you write a program that writes a data file? Can you write a program that squares numbers? Start on one or more of those pieces and post back some actual code.

Also, it is disrespectful to tell us that something is urgent. Your rush does not become our rush.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What have you tried thusfar?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Take a closer look at line 21. The statement meant to be associated with the "if" was being executed regardless. Can you see why?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I am trying to use a "while" loop because that is the chapter we're on.

The input is done by keyboard and the professor has hinted we should use some kind of "while input is good" event test for exiting the loop. We've done that sort of thing for reading from a file, but I don't know exactly how to do it for a cin string.

But with the std::string you have the information about the length already. You should probably use it, like you tried to in your example


while (count < length)

get next letter, if capital then charactrCtr = charactrCtr +1
++count

I don't know the proper command for the "get next letter" bit, though.

Sorry to be a doofus, but I don't understand exactly how to do this, even with your suggestion of "Use a for loop and march through the string by index (in string mystr = "abcd"; mystr[0] is 'a',mystr[1] is 'b')"

Is it possible to initialize count to 1, then use the count to point to the "next" letter?

Yep. That's what I was trying to say. In your snippet above if count starts at zero then userInput[count] would give you the letter at the "count" position (zero based).
So something like

string userInput = "input";
int count = 0;
while(count < userInput.length())
     cout<<userInput[count]<<" ";

would get you "i n p u t". That's all I meant when I said marching through the string. I happened to suggest …

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I agree with Adak's suggestion. Part of the problem is that you are trying to write a string of unknown length to an (uninitialized) char array. Rather than having to "malloc" your way through you could make your array 3 dimensions (of char not char *) and would allow you a fixed amount of room in which to write characters (again the typedef makes things a bit confusing here for you as the programmer).
Either way, you should consider using fgets to read your strings in. An additional perk with doing that is being able to input titles, etc. with spaces in them.
One last thing is, don't call main() like you did on line 199. Let the other functions finish up and return rather than calling Exit().

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Sure, I mean I could probably recreate it (since it's just your includes and a typedef or two) but it'll be faster.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you post up the entire code so I can try it out?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In all 3 cases you are reading your strstr result into pch rather than pch1 or pch2 in the second and third cases. I think you should declare pch,pch1,pch2 outside of the loop and set them to null at the top of the do/while loop. Since you do not initialize any of the pchs there is a good chance that any one of them is non-null when you check them.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
if (pch1 != NULL)
     {
        cout << "My name, you say\n"
             << "It is Jubajee\n"
             << "Cool eh?\n";
             redo = 1;
     }

Are you talking about the above printing out

My name, you say
It is Jubajee
Cool eh?

all at once?
I'm unclear on what you mean by that.

Where does it go after the output of the phrase if it doesn't loop through one more time?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

How are you using "string" in C? Are you compiling it as C++?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There were a lot more errors than 2. In your output function you are missing some pairs of parentheses.

As Excizted mentioned please learn to use code tags. Type in

[code]

//code goes here

[/code]
It makes it very difficult to see what's going on with your code when the formatting is removed.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm basing my opinion on this snippet that I wrote

char cabin[3][13][4];
ifstream ifs("littleswandb.txt");

for (int l = 0;l<3;l++)
	for(int r = 0;r<13;r++)
		for(int c = 0;c<4;c++)
			ifs>>cabin[l][r][c];

for (int l = 0;l<3;l++)
{
	for(int r = 0;r<13;r++)
	{
		for(int c = 0;c<4;c++)
		{
			cout<<cabin[l][r][c]<<" ";
		}
	cout<<endl;
	}
cout<<endl;
}

It takes in the data properly and outputs exactly what was in the file. No need for a "rubbish" variable.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Why have the while loop at all? You have the length of your input on line 17 and all the loop on line 20 is going to do is ask for more input. Use a for loop and march through the string by index (in string mystr = "abcd"; mystr[0] is 'a',mystr[1] is 'b')

Also to assure portability of your code use 'A' instead of 65 and 'Z' instead of 90, etc.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Look at lines 21,23,25. Now look at line 27. You are still not being consistent with which variable is which. It should be [l][r][c] on line 27. If you read along your first output that looks jumbled the proper order of the letters is there but the pattern is all scattered. Unfortunately all you've done is put a band-aid over a huge bug.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

im not sure wat ur asking me here

Was asking if he/she would change the number of rows or what each row contained or really anything that would require the loops to change based on the data. If you've used the for loops below I'll take that as a no.

and i thought about something like this for the for loop instead of the if statements
im testing out now

cout << ch;
             indata >> ch;
             for(int l =0;l>3;l++)
             {
                 //cabin[l][c][r] = ch;
                 for(int r=0;r>13;r++)
                 {
                     //cabin[l][r][c] = ch;
                     for(int c=0;c>4;c++)
                     {
                         cabin[l][c][r] = ch;   
                         cout << cabin[l][c][r];
                     }
                     cout << endl;
                 }
                 cout << endl;
             }

There's a couple of gotchas in the above code. You put the greater than signs by mistake. Also you are inconsistent as to the order of l r c (some of the lines were commented out) Make sure you keep those in the proper oder What you have there is along the lines of my thoughts -- you should just eliminate the indata>>ch and use indata >>cabin[l][c][r]; (or [l][r][c] whatever you decide) in the middle there(line 11, unlabeled ). Changing the variables back to that [L][R][C] order is more in line with how your datafile is laid out -- just be sure to keep consistent!