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

i need some way to print spaces after the snake so it doesnt leave any points behind or a way to make the food function not to generate random points everytime

You know what the last position of the snake was, so just output your spaces after you output the snake.

PeTo. commented: I've done that , but now i need a way for the snake to keep moving without having to press a key a key each time +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You've been given 2 possible solutions. Try one.

PeTo. commented: I tried different solution but hasnt worked for me :D and now i'll try the first solution :) +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You need a FOR loop to move each piece of your snake.

PeTo. commented: i'm trying to make one but out of ideas ! :( +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

what you've shown me is correct!! but is there any way to know that 25-2i or 40-3i will give me what i want???

Yes. Sit down at your desk with pencil and paper and plug values into the variables. See what values are generated and draw out what they indicate.

Pretty much what you'd do in any math class. Works in programming, too.

zeroliken commented: true story +9
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Look up
va_start,
va_list,
va_arg,
va_end

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

I held these until the shakedown was fairly complete. Here are a few of the useful but dropped functions that IMO need to be reimplmented. But #1 is in fact a bug:

1) Any threads I post in are never marked NEW. For the threads I haven't posted in it's a crap shoot whether they are marked NEW or not. Most threads, no matter how many times I mark the forum read, show up as NEW. This might be tied to whether I actually looked at the thread. If I mark the forum read, all threads should be marked as read permanently until a new post is made.

2) The NEW/Target Icon needs to jump to first unread post. The technique with the current setup is
a- click on the message title
b- click on the LAST page if necessary
c- try to remember what message was last seen and/or how long ago the thead was looked at (with vague HOUR and DAY indicators)
d- if necessary, click back a page and scroll all the way to the bottom to find that last post.
This is a HUGE PITA! 2-3 clicks, sh!t loads of scrolling, and memory excercises. Not user friendly.

3) Please add the post number back into the post header. It's really helpful to see what post # is being looked at.

4) I QUOTE a lot so there is no confusion as to what I am referring to in my responses. Highlight- …

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

1.How to get the name including the spaces?

Use fgets()

2.How to press make program to skip question when pressed "n" and when invalid answer like 17u to show error?

The question is unintelligible.

3.How to generate random perfect square no. and how to generate random numbers for (num1,num2,num3) [I always get the same no. when running the program]

When looking up rand(), you undoubtedly came across srand()

4.How to make a timer for the quiz (am currently limiting it to 10 question but assignment need it to end after 60 sec)

use time()

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

Not so sure about DWBB. Looks too much like dweeb.

zeroliken commented: lol +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Yes we can help. See points 1, 2, 7, 9, 12. But don't ignore the rest...

[boilerplate_help_info]
Posting requests for help must be well thought out if you want help quickly and correctly. Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful? Check your post with these checkpoints - what is it you missed:

  1. Ask a question that can be answered. Do not ask
    -What's wrong with my code?
    -Why doesn't this work?
    Anything else that does not give us useful information.
  2. Post your code. If we don't know what you did, how can we possibly help?
    -Use PROPER FORMATTING -- see this
    -Use CODE Tags so your formatting is preserved.
    If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable.
  3. Explain what the code is supposed to do. If we don't know where the target is, how can we help you hit it?
  4. Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
  5. If you have errors, post them! We can't see your screen. We can't read your mind. You need to tell us what happened.
  6. Do not ask for code. We are not a coding …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Look at each character until you find the first character in the find-string. Then check the following characters with the rest of the find-string.
If a mismatch is seen, you haven't found a substring. Continue looking, starting where the first character was found.

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

Your problem is trying to understand the concept by reading code. You need to understand linked lists in general before you deal with the code. Then you will be able to see what part of the code equates with what part of the concept.

Search out a detailed generic explanation of linked lists, then go back to the code and see how the code replicates the explanation.

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

yup, that did it, but just so I have a better feel for it, I seed the random number algorithm thing and then thats the first number the algorithm uses...

No, the seed designates where within the list of random numbers rand() will start. Random numbers are not calculated, they are pulled from a huge list.

a. Why was I getting 8 for every random number when I didn't seed the random number generator/what 'seed' was the generator using in the algorithm before?

Because the default seed always starts at the same place.

b. what is time(0) ? is it the number of nanoseconds that have elapsed since the program was compiled or something? and what does the '0' parameter do?

Look up the time() function. It has nothing to do with nanoseconds...

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

#1: See this about gets() #2: See this[/url] about reading a single character with scanf()/fscanf()

Read a character.
Use a switch to test if it's a TERMINATOR
If so, read next character 
[
   if it's a secondary terminator character read one more 
   [
        if it's a tertiary terminator
        [
            you've found the end of a sentence 
        ]
        else
        [
            you've found nothing...
        ]
    ]
    else
    [
        you've found nothing...
    ]
]
else
[
    you've found nothing...
]
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

for (int i=0; i<=0; i++) -- look carefully...

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

When you go outside the bounds of an array, you simply overwrite variables you shouldn't. You get an exception when you've overwritten enough to leave your dataspace and try to write outside of the program's assigned data space.

Expand your loop to 100 or more and you'll probably get your exception.

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

[boilerplate_help_info]

Posting requests for help must be well thought out if you want help quickly and correctly.  Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful?  Check your post with these checkpoints - what is it [i]you[/i] missed:
[list=1]
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information.
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what happened.
[*]Do [b]not[/b] ask for code. We are not a coding service. We will help you fix your code. 
    If anyone posts working code for you, they are a …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Use Lisp or Snobol

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

Is it Dangerous to Derive from STD? Specifically std::string.

As far as I know, no. That's why objects exist. You start with an object that does most of what you want and add more functionality to it for your specific needs.

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

in coding, how do you actually track down the bug??? example this code where we want to find the quartile....

Too late now, but before you write too much code, compile and test in smaller pieces.
Now, start outputting variables at key places to follow what the code is doing. Compare the values output with the values you calculate they should be.
In this case after the sort display the sorted values.
At line 28 display the value numberstore.size() .
In the for loop, output the values being computed.
Etc...

Vasthor commented: ha3 thnx, never thought 1 month leaving make me forget of this step xD +3
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

No. They wait for the ENTER to be pressed

jaskij commented: My bad :( +4
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

See this, this, and this.
Oh this, too.

DJSAN10 commented: Nice work WaltP :) +5
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Given i = ++i; Does ++ change i?
Does = change i?
If the answer is yes to both, undefined.

Why would it be different from i = i++; ?

PrimePackster commented: That was easy to understand... +3
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I am getting compiler errors

Really? That's too bad. Could you turn your screen a little left so I can see what the errors are?

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

For me the question would be why would you use fscanf() to read a single character when fgetc() does it much more efficiently?

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

Where are you adding the number of evens? All I see is you returning 1.

Also, you aren't breaking out of your recursion.
You test if n is even and return 1.
If n is odd, you call the function again.
But you don't count the evens, and you don't exit/return if you run out of digits.

What you need to do is call the function like you do with your n/10
When n enters as zero, start your return cycle.
If value is even, count it
Return the count.

chaoz014 commented: thank you very much... +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Why are you using StdAfx.h? That's your major problem.

Write the code based on the C++ Standard and the program should compile in both environments. Don't use any of Visual Studio's cutesy enhancements at all.

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

Try printing out a copy of your program, grab some paper and a pencil. Sit down at a desk or a table.

Start at the first executable statement in main() and follow the program statement by statement. Write down the values of all variables. Write down everything that is displayed. IOW, you be the computer and desk-check your program.

This is a fundamental part of programming -- checking your work.

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

IMO, simply reporting it is best.
If it's a seasoned user, go ahead and blast him with rep, then report it.

Don't reply, though. If we decide it should be moved, we need to deal with both posts. If we decide it should be deleted, we need to delete both posts. And in either case, you probably don't want a PM saying something happened to your post via collateral damage.

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

fgets() reads up to n-1 characters or \n, whichever comes first.
Write out what was read.
Read again to get the next batch of characters.
If the first fgets() reads 1/2 a line, the next fgets() reads the rest.

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

Tell you what -- do a search for this very topic and read the scores of previous suggestions that have been proposed. And their responses. Then you can curtail the need to come up with the same ideas that have been mentioned over the past few years yet again and go right to things that have yet to be thought of. :icon_wink:

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

Which is more important, the car or the gas?

What good is your data structure without knowing how to manipulate them via a program? And there's so many programs that don't require data structures.

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

hmmmm....i tried a simple code with unsigned long and it worked until 12!

What's the maximum value an unsigned long can hold?
What's the actual result at 12?

cn v sumhow ... bt any easy diff way possible?

And what does this mean? Is it Swahili? Reread the member rules about posting in English.

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

Who said //?

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

[boilerplate_help_info]

Posting requests for help must be well thought out if you want help quickly and correctly.  Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful?  Check your post with these checkpoints - what is it [i]you[/i] missed:
[list=1]
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information.
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what happened.
[*]Do [b]not[/b] ask for code. We are not a coding service. We will help you fix your code. 
    If anyone posts working code for you, they are a …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

1. The problem you have is gets catches the EOL you get after hitting return for the number of the kids. Adding something like getch() before that gets() should fix this. Or just use gets() twice.

Using gets() at all is dangerous -- here's why. And gets() "does not catch" (whatever that means) the EOL. getch() is a completely non-portable solution and exists in very few compilers. It's best to learn proper techniques because learning to use gets() and getch() will cause major problems when you start programming for real.

2. Use string instead of string.h - the second one is legacy AFAIK.

No, string.h is the header used for c-strings. string is the header used for C++ strings.

3. Don't mix C++ and C I/O. Use istream::getline() or getline() from the string library.

True. If using getline in one place, why use gets() somewhere else?

jaskij commented: Guess I made fool out of myself, thanks for claryfying :) +3
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Feel free to use this boiler plate for any posts that you deem could use it:

[boilerplate_help_info]

Posting requests for help must be well thought out if you want help quickly and correctly.  Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful?  Check your post with these checkpoints - what is it [i]you[/i] missed:
[list=1]
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information.
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what happened.
[*]Do [b]not[/b] ask for code. We are not a coding service. We …
jonsca commented: Wha- I'm supposed to _read_ all that? :) +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Hi, everybody.

I am reviewing some old code and two questions came to mind.

1) Is it better to use “\n” or endl?
"\n" seems to be working just fine, but most code samples I see in books nowadays use endl. What is the difference?

\n simply adds a newline to the output buffer.
endl adds a newline and flushes the buffer (forces the output to be displayed).
Use ENDL.

2) For multi-line output statements, is it better to avoid repeating the cout part of the statement?

I think that's up to the programmer's personal preference.
I'd tend to use the multi-line cout myself.

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

in DisplayResult() , what's the value of optr?

SoftShock commented: ty! +1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

gets()
scanf() -- read the full series
void main()

Might as well see Formatting too.

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

if(strcmp(s.name, stdname)==0)
is this statment is correct? i am having an error while executing this statment.. i have givn its headerfile

Depends on how s is defined.
Depends on how name in s is defined.
Depends on how stdname is defined.
Depends on what headers are included.
Depends on what the error is since there are hundreds of error messages possible.

As it is, the statement is syntactically correct.

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

My point is we do not condone posting working programs as a starting point for a poster. We help him write his own code. The program does a large chunk of what the OP needed -- enough that the homework would not be his.

If cangan had posted psuedo-code, I would have no problem with the post.

My comment stands.

PrimePackster commented: Agreed +3
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Try this

And what grade do you expect to get for doing sodha125's homework for him? Around here we call that cheating... Good job!

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

It's just Opera telling you to look forward. Leave the past behind you... :icon_twisted:

diafol commented: :) +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Some people it's inherent. Other can never understand it. You seem to be somewhere between and haven't worked at developing it.

Have you ever done what I just did with any code? If not, you have not been a programmer. A programmer is a detective that searches for reasons why things work and don't work. It looks like you haven't done that yet. Starting now, be much more analytical in all -- that's ALL -- the code you write. Once you get something finished, make a copy and rewrite a small section with a slightly different idea. Then analyze the results. Why did they both work? Why did one work and not the other? Narrow down the difference and keep a journal of the things you find so you can refer back to them and not make the same mistake 5 more times.

Here's an example. Remember that link I gave you? Now here's your working code with a minor change removing unnecessary lines:

while (file)
{
    file.read( (char*) &rec, sizeof (account) );
    if(!file.eof())
    {
        rec.display();
    }
}

We now know why this didn't work:

while (!file.eof())
{
    file.read( (char*) &rec, sizeof (account) );
    rec.display();
}

But why does this work? It still uses .eof() ...

file.read( (char*) &rec, sizeof (account) );
while (!file.eof())
{
    rec.display();
    file.read( (char*) &rec, sizeof (account) );
}

When something doesn't work as expected, don't just muscle through to the answer, changing things and hoping it worked.
1) Completely …

deceptikon commented: A case of mistaken identity, I think, but great reply nonetheless. :D +3
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

superblock - Do you need it? You're designing your own system, aren't you? Why try to duplicate something else, especially if you don't understand it?
boot block - You don't need it. You aren't booting anything. Assume this is a secondary drive. KISS.
inode list - This you need in some form -- of your own design.

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

Commenting your code AND formatting it properly (second suggestion) helps a LOT!!!

for (int x=0;x<10;x++)
{

cout<<"enter:";
cin>>input;         // input a number
if (input<-1)       // if number is -2, -3, -4, and so on...
nega++;             // increment value to count it.
else if(input>=0)   // otherwise if 0, 1, 2, 3, and so on...
posi++;             // increment value to count it.

// what about -1?
// is 0 considered positive?
// The above comments are what's happening. Do they in fact explain what you want to happen?
}
cout<<"positive:"<<posiAr[posi];    // what is the value of posiAr[posi]?  I don't see anywhere 
                                    //where the posiAr[] array has any values in it at all.
cout<<"negative:"<<negaAr[nega];    // Same here.
getch();
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Now that you've figured it out, go back and up-vote more of my posts! :icon_twisted:

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

you should use flag and store 1 if 1st date is smaller.and use break; in if block;

Have you ever used a break in an if() block? It doesn't work.

I don't see any validity checks done for your dates. He can enter invalid dates like 33/33/2012.

I would assume validity checks in this program are moot. It's just to figure out how to compare dates in general

day1 = yyyy1 * 10000 + mm1 * 100 + dd1
day2 = yyyy2 * 10000 + mm2 * 100 + dd2

Check which is greater out of day1 and day2. So simple, isn't it :P

Nice. Simple and workable, even with invalid dates. I'd use some parentheses though. Makes the equation easier to read.

But there is another potential error in your program. Your variables mm1, dd1 are declared as integers and in your console out put you ask the user to enter in mm/dd/yyyy format. So for September, the user will enter "09". But since mm1 is declared as int, "09" will be treated as octet number and you'll get run time errors, since 8 & 9 are not allowed in octet system. So better use strings.

Completely untrue. Write a test program and see.

subith86 commented: thanks for the info +3
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Have to work too hard trying to follow the code with that awful indentation. See this, reformat and try again.