WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What is the type of your parameter in the call: activities[0].action ? Isn't this a single character? The function itself doesn't want a character as a parameter. What does it need?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Found it. Javascript got turned off...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

It's because x is a pointer, not data. It needs to point to data. Without the new (or &a as suggested) there is no data and the pointer is pointing into the Twilight Zone. And you can't load data into the TZ.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Why do you need pointers at all? What's wrong with

int x;
int y;

That way you don't have to create the variables to load into the pointers?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

After so many years in the computer field, that's usually the second thing I try. The easy stuff (booting/reset) are always long before asking what else... :icon_wink:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You need to think about what you're doing, not just toss anything together and pray.

for (n = 0; n < 7; n++){
               inFile >> currentDays; 
               }

Why are you reading 7 separate values into one single integer?

also, format your code. We can't tell if you have separate loops or nested loops. the code is very hard to follow.

And if you have errors, post them. Exactly as they are displayed to you. I know here's at least one in the code you posted and it's because you weren't careful about the last change you made.

Salem commented: Nice +20
VernonDozier commented: They should pin your formatting thread to the top of the C++ section. +11
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

This was working fine a few hours ago. But now:

Editing hot-keys and icons do not work
Forum Tools simply refreshes the page
Folder Icons are inactive
I have no mod tools on profile page
On my own profile page there is a Send Message link and nothing else.

Basically, a lot of functionality is completely gone. The pages look fine, but no longer work. Ctrl-F5 does nothing useful.

Any idea what happened?

jonsca commented: Could you post some relevant code? (couldn't resist) +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What have you found out? What format is the system time if you need to add to it? What function(s) do you need to call?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I removed the return statements but I'm still getting the same problem. What else am i missing?

Formatting. Without formatting your code is extremely hard to follow.

If you suspect your input is not working properly, display what you input to see if you are right. That's the easiest way to tell when something is not working properly -- output the variables in question and see what they are.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Nowhere. Without the code that is needed to run the functions in the header, the header alone is useless. And even if you did find the code, it probably can't be plugged into your compiler.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You need two matrices, one holds the current generation, other to hold the new generation as you create it.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

fflush(stdin) -- See this
getch() -- See this
while (!feof(F1)) -- See this

BestJewSinceJC commented: Good help to the OP +5
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Don't you need to ignore non-letters? For the sentence MADAM I'M ADAM, your code would compare:

M-M
A-A
D-D
A-A
M-" "
" "-M
I-'

would it not? Definitely not a palindrome.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Or
use fgets() to read the file line by line.
test each character to see it they are all digits
if all digits, copy the line to an array to be sorted and output.

There is no need to convert the numbers to ints although it might make the sorting easier.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

To get the best help here, it's best to give us an idea of what the problem is, rather than making us guess. What do you need help with? What's going wrong?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
int add()
{
      int num, sum=1;
      cout<<"how many numbers would you like to add?\n";
      cin>>num;
      for (int i=1;i<num;i++)
      {
          int array[i];
          sum+=array[i];
          }
      cout<<"Your new number is  "<<sum<<"\n\n\n";
}

Three problems with the ADD function
1) What he said above
2) starting sum at 1 will give you the wrong answer every time. Adding 5+4 will give you 10.
3) There are no values in array so you are adding garbage.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

> Only recently, DOH became a word in the dictionary.
If you can cite any dictionary supporting that, please do.

http://www.oed.com/newsletters/2001-06/doh.html
Definitive, I think.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Much better! I personally prefer the { on a separate line (like Vernon's code) but that's a preference. I just find code easier to follow that way.

It also alleviates this problem:

if (userNum == ranNum) {
	    {
		cout << endl << "Correct!" << endl;
		cout << "You win $" << bet << endl << endl;
		bal = bal + bet;
	    }
	}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

01000100 01100001 01101110 01101001
01110111 01100101 01100010
01010010 01101111 01100011 01101011 01110011

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

No. Copy the answer code to tmpAns. Then test for black in a loop with:

If guess(i) == tmpAns(i)
    black = black + 1
    tmpAns(i) = -1      // answer code is found, don't reuse
    guess(i) = -2       // guess has been used, don't reuse

That's the entire black test.

White test takes a nested loop, but it's identical..

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

It's still bad. I added a link for a reason.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I can do it!

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

The way this site works is
1) You ask a specific question that can be answered.
2) You post the code segment that you are working on that doesn't work
3) You explain what it's doing wrong
4) You explain what it should be doing
5) Add any additional details that will help those if us that didn't write the code understand the code and the task.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You should concentrate a little more on your formatting. Indenting 8 spaces is too many for most situations. And your indentation is a little inconsistent.

See this for some ideas. There are many other suggestions on the web.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

If you say so. All I know is my version uses a total - that's total - of 3 arrays, and 5 variables.

char  pattern[NUMVAL];     // The answer key
    char  patterntst[NUMVAL];  // Temp version of the answer key
    char  guess[NUMGUESS];     // The user's guess
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Oh.... No I was confusing them with he .obj files I've dealt with since the 70's -- output from compilers. .O is only Linux, .OBJ was every other system I've used.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

WaltP your way doesn't even work... you need the 2nd array to say where you already guessed that position or not.

Sure it does. You only need to test the current values entered against the answer key. Based on what I see in your code, it's 10 orders of magnitude more complex than it needs to be.
bool**, malloc'ed bool arrays, triple nested loops -- all unnecessary. You need to think simple.

And in MM, you don't return the positions correct, only the count. I don't think the 2nd array is necessary.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I always thought language was an evolving and growing thing.

In the 30's, the proper word was clew until the magazine Clue was started and the 'wrong' spelling became accepted.

Until computers became popular, input wasn't a word.

Years ago, gay meant happy.

Only recently, DOH became a word in the dictionary.

IMAO, infraction is used perfectly well for the evolving language we are currently involved with.
(which used to be bad English but is no longer -- prepositionally speaking)

Nick Evan commented: Here he comes to save the day! +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

um, did you try "double-clicking" the file?

.obj files are written in plain text.

Mine aren't. Mine are all binary.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

In addition, you cannot read into argv. That's undoubtedly where it's going wrong.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

So I think i figure it out... But when my population is too big the answers are screwed up. :(.

Here's my code:
Main

int Mastermind::getblackpegs(int* guess)
{
	int blackpegs=0;
	for(int i=0; i<4; i++)
	{
		if(guess[i]==answer_[i])
		{
			blackpegs++;
		}
	}
	return blackpegs;
}

int Mastermind::getwhitepegs(int* guess)
{
	int whitepegs=0;
	bool guesscounted[]={false,false,false,false};
	bool keycounted[]={false,false,false,false};
	for(int i=0; i<4; i++)
	{
		for(int j=0; j<4; j++)
		{
			if(guess[i]==answer_[j]&&!keycounted[j]&&!guesscounted[i])
			{
				whitepegs++;
				guesscounted[i]=true;
				keycounted[j]=true;
			}
		}
	}
	whitepegs=whitepegs-getblackpegs(guess);
	return whitepegs;
}

That's soooooo much better. Short and sweet.

White Pegs is a little odd.
1) You only need one boolean array, not 2.
2) Outer loop should go through the answer pegs.
3) Inner loop through the guess pegs.
4) The boolean should match the guess peg/inner loop.
5) Return the number of pegs that match (change the name of the function)

This way you have two function calls in the calling function:

npeg = getMatchingPegs()  // get the number of pegs that match
bpeg = getblackpegs()     // get the number of pegs that match in position
wpeg = npeg - bpeg        // get the number of white pegs

This keeps the functions simpler and you don't have to call the black peg routine twice.

By the way, what's with all the underscores?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What you are attempting to do -- if it worked -- is corrupt your file by overwriting the next line of data with ANNOUNCED
You need to open a second file and after reading a line, write the line to the new file. Then do your test.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Look up the syntax for a scanf() statement

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You don't need to complicate it so much.

Loop 1 through the answer array i=0-3
    Loop 2 through the input array j=0-3
        if answer[i]=user[j]
                negate user[j] (flag as seen)
                increment count
                exit loop 2
    next j
next i
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Why resurrect it just to retire it? Strange. Later--

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

If anything, people should post more code snippets - even if it is obvious and easy to the person posting it, there are always tons of people who it could help.

But only if they come to the forums within a week or so of the snippet posting, otherwise they get lost in the annals of time. If they were organized and referenced somewhere, they'd be more useful.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

They won't click the link. They don't care. Remove the Code Snippet option if there are fewer than 20 posts.

jonsca commented: It would save me from having to come up with "clever" ways to report ones that aren't code snippets! +0
Ancient Dragon commented: Good idea :) +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

1) Count the numbers that occur in both arrays -- correct pegs.
2) Count the numbers that occur in the correct position in the arrays -- black pegs.
3) Subtract the black pegs from the correct pegs -- white pegs

Answer: 2658
Guess: 6625

Correct: 3
Black: 1

Therefore-
White: 2

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

First, reformat the code to take out all the unnecessary blank lines.
Second, ask a specific question explaining specifically the first thing you need help with
Third, point out where in the code you attempted to solve the problem and what happened

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Use an if statement and increment a counter

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

If you'd format your code I'd be happy to take a look at it. As it is, I'm not going to struggle with it.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Integers don't have decilam places. You'd need to convert the variables to double.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

i have written this code but it isnt working properly...... plz check it

Check it for what? Are we looking for something? I don't understand whay you need us to 'check it' for.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Sure. See this.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

That's a good task. If you need help, let us know what you need help with and we can help.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Hi

we have a buffer say char array.[1].so the size will be 1 byte.

Why? An array is multiple bytes. 1 byte is a byte, not an array.

I have a fleet of cars -- it's a Ford.
I have a pride of lions -- his name is Leo
I have a pair of socks -- where's the other pair for my left foot.

jephthah commented: jesus christ, it's a lion get in the car!!! +7
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Because you cannot access a character array as if it is one thing. You wouldn't expect to do this, would you?

void swap(int *s1, int *s2) {

 int *temp;
 temp = s1;
 s1 = s2;
 s2 = temp;
}

A 'string' is just a character array that has \0 in it..

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

So what you're saying is my suggestion was of no help. Sorry about that..

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

wow, 123 views, no response, wow...

No response? Really? What about

Do You Have any idea on how a vector works?

It seems the no response was on your end, bucko.