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

Yes. \ is for Windows. / is for Linux.

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

Love 'em or hate 'em, certifications are a fact of life.

So is gangrene.

Kinda like a pistol...if you have the cert but not the knowledge it's like having a gun but no bullets.

Or, more to the point, like having a gun with bullets, and not understanding what you have. You're going to hurt someone... :icon_twisted:

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

Thanks for the reply WaltP, but I don't have an .EXE file. I'm running a.out from the terminal in order to execute my program.

Since 99% of the posters here use Windows, forgive me for not realizing you are running on Linux.

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

The language definition doesn't have an equivalent, so unless you're sure the behavior isn't needed, this is a bad argument for such advice. Depending on how getch() is used, it may or may not be superfluous though. If it's superfluous then there are grounds for removing the feature entirely in favor of portability. But that's not really your call, is it? ;)

Hence my phrasing: "you should consider not using it at all" :icon_wink:

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

Very nice. However, somewhere along the line, in the zoom functions, times became an asterisk and center became a cent.

Well, the times sign is an asterisk, so that makes some sense.
And you probably zoomed in so far the er couldn't fit on the screen anymore...
:D

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

Seems to me the only way to find a "car spot for the user" is to search the parking structure and note all the empty spots. A robot or flying drone would probably be best.

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

You can just press CTRL + ALT + DEL.

Find the process that is blocking you to delete that file then End Task it.

And how do you "Find the process that is blocking you" -- is it really obvious? :icon_rolleyes:

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

It's in the same directory as the .EXE file.

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

Since getch() is not and never has been part of the language definition, you should consider not using it at all.

The link claims the conio.h is deprecated. It is not deprecated. It has never been defined by C nor C++. It's simply an add-on header extremely few compilers defined.

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

adityatandon, what part of

Sorry! The strings in question are single lines of no more than 30 characters.

did you not understand?

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

Pass the inFile to the function.

Also, read this

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

You didn't take Mike's hint. Here's mine:

[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 …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

So, when making an array to search, i always have to sort it first?

Yes. It's impossible to do a binary search on an unsorted list.

I could get this binary search to work... no matter what number i enter it will say
"not found" even if its in the array; until, i sorted the array before searching.

Now is a good time to add debugging statements to follow what the code is actually doing.
Before and after every important decision, display the variables that are affected and study the values to see which ones are not as expected.

You're going to have to desk check your program using this technique -- one of the most important debug techniques in your programming arsenal.

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

> "I can't remember it just now, but I'm sure there's a good reason for that" (basically the argument deceptikon makes): Assuming there was a good reason behind it, then they should care about remembering it and should be willing to spend some time analyzing the code to find out what that reason was (if they are not willing, then they are lazy slobs, programming skills have nothing to do with that). If there was a good reason then, there should still be a good reason today (unless it has become obsolete), and therefore, you should still be able to figure out what that reason is today (hopefully with the help of those who wrote the code in the first-place).

This analysis I disagree with -- at least on the surface. If the code in question is working and no changes are required to correct errors or make enhancements, why bother spending time understanding why something that is working used the technique in question? It's immaterial at the moment and not worth a senior's time nor effort to dig into it to assuage someone's curiosity. They have more important things to do than relive the past.

On the other hand, if an error or enhancement is being made, understanding the code is extremely important -- to make sure the new changes don't have hidden complications.

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

You have 4 months of experience, therefore you need to use these programmers as learning tools. If you see something weird, take it to them and ask them why. Use it as a learning tool. A few things can happen:
1) you learn why they did it and you see why your idea was in error.
2) they learn a better way to do something.
3) you both learn that there is more than one way to do anything.

Be sure you go to them expecting to learn, not to point out how dumb they are.

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

I just can't think of a better evaluator, do you have any ideas?

Use a magic square:

[b]
6 1 8 
7 5 3
2 9 4
[/b]

All directions add up to 15
If you see 2 consecutive chosen values and 1 not chosen that equal 15, the unchosen value will win.
By the way, the center position is the best opener. It has more ways to win than any other position.

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

A user doesn't enter a data type. They enter data that is put into a variable which is defined by a data type at compile time. So at compile time the data type size is already defined and can be output using sizeof([I]datatype/variable[/I]) .

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

You don't type it in... You copy/paste it. Rather than save the link, save the text itself.

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

I repeat

... try following your code with paper and pencil to see what the values are doing. This is called debugging and is a critical component of programming.

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

No. Read what deceptikon said, work at understanding his meaning, and fix your code.

Or try following your code with paper and pencil to see what the values are doing. This is called debugging and is a critical component of programming.

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

You are all wrong -- except for deceptikon. The value cannot be determined with any surety. See this

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

I have an alpha beta interface and have implemented a tic tac toe class from it. For some reason my AI tends to occasionally make stupid moves (such as making a fork rather than blocking a 2 in a row) I was wondering if anybody can see where I went wrong:

...

I really cannot see why it is that my TicTacToe AI that usually makes the best possible move should occasionally make a stupid move. Any ideas?

Well, with nothing to go on but the term 'stupid move' (not a clue what a fork is) and 300 lines of uncommented code with no indication of where to look, it's fairly time consuming to try to understand all the code you wrote just to answer this question.

Try pinpointing where the problem might be and make our life easier...

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

How is 'string' defined for this purpose? Technically any text file only has one string, the entire contents of the file. Another common method is reading words where a 'word' is any unbroken sequence of non-whitespace characters.

Exactly. A 'string' can be
- a single word
- a single line
- a sentence
- a paragraph
- a page
- entire file

Be explicit...

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

If one matrice array is :

array<int,2> ^ matrice_mixed_nums = gcnew array<int,2>(5,7);

what should be the second's size

Count the rows that are not all zeros...

Ps. matrice_mixed_nums are filled with random nums

Then it's extremely probable that there are no rows with all zeros.

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

... no matter where I look I can't find a thread on any site (not just daniweb) that explains how to do this in visual basic and not vb.net or vbscript....

Basically what I'm trying to do here is take a file that is made in another portion of the program and delete the first two lines out of it. From what I can tell everything else works, including the portion that copies the data from one file to the other. I just don't know how to get rid of those two lines in the first file.

Any help would be much appreciated. Thank you. -Zoidmaster

First of all, the technique is the same no matter what language you use.

Granted, I didn't read all these posts because the solution is soooo simple, and you claim you have "the portion that copies the data from one file to the other" working, so the solution is

Ready...?

Read the first two lines of the file.
Now copy the rest of the file with the portion that works.

By reading the first to lines, they are no longer available to be read so will be gone from the copied file.


IOW, read the file; write only the lines you want copied, don't write the rest.

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

What is apparent is that there are differing views on what the evaluation. The solution is simple, if there is any ambiguity then use brackets.

Doh!!!

#include <stdio.h>

int main()
{
    int x=3;
    int y=4;
    int z=4;

    printf(" z >=  y  >= x  %d \n",  z >=  y  >= x);
    printf("(z >=  y) >= x  %d \n", (z >=  y) >= x);    
    printf(" z >= (y  >= x) %d \n",  z >= (y  >= x));

    return 0;
}

Results:

z >=  y  >= x  0
(z >=  y) >= x  0
 z >= (y  >= x) 1

So obviously left to right...

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

4>=1 is not true. So you get a 0.

4 >= 1 is false, so the result is 0.

Since when? Have they changed something since I've been in school?

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

Also please edit your first post by aligning the code properly and wrap [code] tag so that it is easily understandable for us to analyze.

I don't see where you did this. If you want help, make your code readable so we can understand it.

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

You don't have to mess with ASCII codes.

So, since you completely confused us, how about restating your problem so we understand exactly what you can and can't do. Can you use the % operator?

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

endl, in my opinion, helps skip lines in the code. It also helps organize code because when you cin >> x_integer;
cout << endl; or cout << endl << endl; (skips 2 lines)
can make your code look cleaner and more organized. In my opinion anyways.

I have no idea what you are trying to say.
Skipping lines in code is a bad thing. You don't want to skip lines of code, you want to execute every line.

cout < endl; doesn't do anything to your code. It only affects your output.

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

I need to write a code that takes a percentage and converts it into a letter grade. The problem is that I'm not allowed to use if statements.

85-100 -> A
75-84 -> B
65-74 -> C
55-64 -> D
0-54 -> F

One attempt I made was changing the numbers to their ASCII code but the 15 percent range for A and the D to F makes the method not work.

A = 65; B = 66; C = 67; D = 68; F = 70

letterGrade = 69 - (int)(percentage / 10 - 4.5);

Works from 94 to 55.

Any ideas?

Looks to me like you're on the right track, just need to zero in on the correct equation and technique.

One thing to think about is an array to hold the letter grades. How can that idea be used?

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

Agreed.
Make a function.
Test year -- return false if bad
Test month -- return false if bad
Test day <1 & >31 -- return false if bad
Make switch for:
31 day months
30 day months
Feb...

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

There's one other structure that is available -- a dequeue (pronounced DECK).
Items can be added and removed from either end. This may be what you need.

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

By the way, it's LIFO (Last In First Out), not LCFS

Moved...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
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

Open the input file
Open the first output file
Read a line
Count it
Write the line
Read a line
Count it
Write the line
Read a line
Count it
Write the line
-- when the count gets to one of your magic numbers
Close the output file
Open the next output file
Continue reading, counting, writing...

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

Add another getline() just before the return in main....

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

Look up the MID, LEFT, RIGHT and INSTR commands.

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

Write a couple test programs to understand how input works.

1) use cin in a loop to read and display what is read
2) use getline() in a loop to read and display what is read
3) same with other input commands you know

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

Use getline()

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

OK. I tried...

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

Ever hear of arrays?

How do you expect to debug a statement like

while(a<1 || a>16 || b<1 || b>16 || c<1 || c>16 || d<1 || d>16 || e<1 || e>16 || f<1 || f>16 ||g<1 || g>16 || h<1 || h>16 || i<1 || i>16 || j<1 || j>16 || k<1 || k>16 || l<1 || l>16 || m<1 || m>16 || n<1 || n>16 || o<1 || o>16 || p<1 || p>16);

and at the same time notice that one error is the ; at the end?

You need to use the KISS principle, and a separate variable for each value is not it.

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

Hey there,I'm looking for assistance with my simple code here.

If you can't figure it out, it's not that simple, is it? :icon_wink:

Why do my integers ( x,v,z,d,e,f,g,h ) suddenly change when the program reaches the " printf("The decimal value is... " part? Is there something I'm missing?

Define "suddenly change"? What did they start out as and what do you think they became? Since you never output any of those variables until after you scanf() 'd them, how do you know anything happened to them?

Sorry, but based on the code, the question is nonsensical. Think through the question again and restate.