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

So when you find a / read the next character.
1) If it's a *, read until */
2) If /, read until EOL
3) If neither, continue on.

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

Time to back up...

Read a line
Search for // then /*
If you found one of them, process that comment style.
If you found both, which one's first? Process that one only.

If you get a // the rest of the line is a comment -- done.
If you get a /* search for */ -- everything between is a comment
-- if */ not found, read another line and search again. Keep it up until you've found it.

Remember, this is legal:

if (val /*the number being tested*/ != 0 /*has a good value*/ (
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

1) Format your code
2) main() is not a void
3) Don't use conio.h because it's non-standard and only a couple compilers have it defined
4) The .h version of C++ headers have been replaced years ago

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

Which date? Creation? Last Write? Last Access?
All seem important to me, albeit to differing degrees.

And what are you considering a header?

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

Great! You should have said so and mark the thread SOLVED...

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

It also helps to comment your own code. Then you can use it to test itself.

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

Much better. I assume it's working fine now?

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

I need to two loops in the switch correct? one to read in the information and one to put the output in the struct.

Why? What's the switch supposed to do?

You aren't thinking this through. You're taking a poorly designed program and trying to shoehorn in fixes that may or may not work. You'll never get it this way.

You need to take your problem statement and sit at a desk (no computer) and start writing down the individual steps you need to do to accomplish the task. Smallest steps possible.

Then order those steps in a logical order.

When -- on paper -- your algorithm (the list) looks like it will do the job, now go to the computer and code it. You can do it the hard way and plagiarize what you currently have, or start over.

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

Sorry, I disagree with most of what therockon7throw said...

We call C++(C PLUS PLUS ) because it has been taking his way from old C, and has brought many many concept , OOP (Object Oriented Programming) , STD, ADS , template and finally Meta Programming. C++ without these features would be just C.

This I agree with.

With C you write a program, but with C++ you manipulate the program itself.

This I don't. You aren't manipulating the program, you're manipulating the data via the programming.

So to summarize, learn first C++ as well as you can, and if you are a master of C++, there is no language on the earth that you can not learn in just a week.

And this is just blatantly wrong. There are many, many languages that knowledge of C++ won't help one iota in learning.
Lisp
Snobol
Bliss
RPG
Assembly
Cobol
Prolog

just to name a few.

And the argument "I've never heard of them" doesn't apply. They exist and are in use.

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

the obvious would be to compare the entered_PW to the actual_PW but looking back over the rest of the code i think i forgot to assign each digit in the actual_PW to the random 1-3. how could i do this? or is

actual_PW[index] = random_Nums[index];

sufficient?

That's seems to be exactly what the function is for, so yes.

in this iteration it couldn't return true, and that is mostly because i hadnt fully figured out what i needed to compare to get the true.

heres an update on that function

bool isValid(int actual_PW[], int entered_PW[], int random_Nums[])
    {
        bool valid = false;
//*****************************This is where i'm having trouble**********************************
        for (int index = 0; (!valid) && (index < sizeof(actual_PW)); index++)
            {
                actual_PW[index] = random_Nums[index];

                if (entered_PW[index] == actual_PW[index])
                    {
                    valid = true;
                    }
                else
                    valid = false;
            }
        return valid;
    }

Your thinking is backwards. If any values are TRUE, this function returns TRUE.

When creating a function that returns an all-or-nothing comparison, like this function, it's best to start by setting the response to 'all' (TRUE). Then during the the testing, if any value fails, a single FALSE comparison sets the result to FALSE.

The way you have it, the result assumes FALSE. Then during the the testing, if any value succeeds, that single TRUE comparison sets the result to TRUE. Clearly not what you want.

Think of this as an ANDing function. Any fail returns FALSE, All successes return TRUE. Yours is an ORing function.

But …

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
bool isValid(int actual_PW[], int entered_PW[], int random_Nums[])
    {
        bool valid = false;
//*****************************This is where i'm having trouble**********************************
        for (int index = 0; (!valid) && (index < sizeof(actual_PW)); index++)
            {
                random_Nums[index] = actual_PW[index];
                if (entered_PW[index] != )
                    {
                    valid = false;
                    }
            }
        return valid;
    }

#1) If you are trying to compare the password entered (entered_PW[]) with the actual password (actual_PW[]), why is random_Nums[] needed to check validity?
#2) What is the purpose of random_Nums[index] = actual_PW[index]; ?
#3) What is the obvious comparison for entered_PW[index] in the IF ?
#4) If you only set valid to FALSE, how can it return TRUE?

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

And I don't understand what your problem is.

You have all the values accessible.
You know how to convert a control's text field into a value.
You know how to add two values.
You know how to load a value into a control's text field.

Clearly you are having a specific problem that your general description does not address.

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

Run the program sir and enter any file name with extension file of txt and choice number 1 add records then desplay the record by chosing number 3 that code is in parallel i want in vertical.

No sir, you post what the program displays and what you want it to display. That's the price of asking for help -- giving us the information we need to understand.

Be sure to use the proper tags so we see exactly what you want us to see.

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

1) Your switch function has no value at all for rank
2) You return a nonexistent variable named rankPay

Think it through again. What values do you have available in the function? What values do you need to have for the calculations? If you don't have them in the function, how can you get them there?

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

We don't bump here.

The reason I haven't answered is your comments were nonsense based on my previous post:

That just multiplies the first input by two.

And your following question makes no sense for anyone with 2nd grade math:

How can it add new items inputed from the user in the textbox to the labels? So lets say i put in 35, it will show subtotal of 35, tax of 1.05, shipping 15, and total of 51.05. Now if i put in another number like 40 I would want it to add it to the subtotal, tax, and total of the first.

Use the + sign somewhere in your code to add the new values to the old values.

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

Calculate the new values for subtotal, tax, and total and put them in whatever control displays the values txtSubtotal.text = subtotal or lblTax.caption = tax

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

Set a maximum of 100 people. I'm sure that's more than anyone simply testing your program will enter, and if they try to enter 101 a simple error message will prevent it.

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

Maybe more information would help. Like why you need the \n when getline() clearly reads the entire line.

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

Can't you come up with something better? Sounds like Miss America... :icon_rolleyes:

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

I don't know what that means in relation to my comment.

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

I have the searching part done, but my bubble sort isn't working right. It seems right in my head, so I'm not sure what's wrong.

Then get it out of your head and on your desk with pencil and paper. The mind is a very bad analog for the computer.

When programming, the last thing you do is type the code in. Before that you need to sit at a desk and write down your steps, eventually convert that to code, and execute that code line by line on paper to iron out the details and problems you forgot about.

Once it looks good on paper, that's the time to type the program in.


You'll thank me later... :icon_wink:

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

randNum = (rand() % range) + firstNum;

range is the total number you want to generate
firstnum is the beginning number of that range

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

You aren't reading the NewLine after the numbers. When reading numbers, the system stops reading when the number is finished.

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

fgets()

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

Set one value before you start testing.
Only reset the value when the condition you need to test for is met.

In this case, assume it's prime, set value to IsPrime.
During the test phase, any other factor sets the value to IsNotPrime.
At the end, if value is IsPrime, no other factors have been found.

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

Yeah... but just using the code i gave above is a substitute for all of it..
Isupper resides in the standard library with the same procedure u mentioned here.. Why write the whole code, when there already exists a direct function for it ??

Yeah... and by just using the built in functions, what do you learn? How to use a built in function. What if your next language doesn't have that built in function? You can't program the task...

And

Since we appear to be giving away code these days

thread closed...

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

Who said //?

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

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

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

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

Pass the inFile to the function.

Also, read this

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 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

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 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

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

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

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.