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

chPtrs[j] = new char[strlen(tmpStr)]; -- you forgot the extra character for the trailing \0

for (int j = 0; j<strlen(*chPtrs); j++) -- what is the value of strlen(*chPtrs)? Do you really want the string lenght of a pointer? Wouldn't the length of a string be more useful?

And in that loop, why are you outputting exactly 5 characters? LION only has 4 characters, BAT has 3, MONKEY has 6. I'd suggest another loop, using strlen() of the string you are outputting.

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

I did not do any HW for others. He tried and need help and I get him a way to know what is his wrong. There were several mistakes in his code and I do it for him.

You said:

This is working code on Watcom C/C++

so yes, you did.
Correcting all his mistakes without pointing out what they are is doing his work.

Simply pointing out his mistakes and suggesting corrections -- no code -- is helping.

Remember, "I do it for him." is doing it for him, not letting him do it.

nitin1 commented: awesome explaination of doing homwork ;) +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Or use getch() :twisted:

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

Then you still did something wrong. Since we can't see what has changed, we can't offer suggestions.

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

Of course. Read my previous post.

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

Hmmm, I take back my apology. Look in the damn book!!! :P

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

for (int j = 0; j<strlen(tmpStr); j++)
Why are you going through tmpStr? Isn't that simply the string you used on input? It has no bearing on your word list once input is done.

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

The element I am assuming is the pivot point?

No, it's not a pivot point. It's just a number you need to find.

Basically I am asked to find an element in a sorted array and that is it.

What element? You don't seem to be looking for anything. You need a target number to find in the array

int array[size] = {4, 8, 0, 1, 3}

I thought you said sorted array...

It's asking you to search for a value in the array.

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

Look at it this way.

A declaration is like your street address. It isn't where you live, just a reference to the location. It simply says that your place (or the variable) exists somewhere.

A definition is the house/apartment itself. It holds all your stuff -- like a variable.

You can have your address (declaration) on letters, your license, in your bank account, many places. But your house (definition) can only be in one physical place.

int x; is the definition.
x = 10 is not a definition. It's an assignment. Like buying a new chair. It just goes into the space that's defined.

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

OK, sorry. Ignore my previous post. I shall restate:

No, there are no functions called error() and keep_window_open(). They must be something he wrote for the book.

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

The statement if (!string || !*string || !isdigit(*string)) alone tells me you have no idea how to handle an array of characters. You need to read up on 'strings' and pointers to understand them. Then what you need to do should be clearer.

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

Yes we can, if you help us understand your difficulty.

All it takes is a FOR statement and the % (modulus) operator.

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

Does this mean that I have to find alternative functions to the ones mentioned in the book?

No. You need to read closer. You should find that he provided code for these functons.

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

What happened to

The input of this function should be two pointers (pointing to original array and reverse array).

You need to start reading the assignment and doing what it asks for.

And why 6? Is that a magic number somehow?

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

Ok. My program specifically says that I need to put the characters into an array and when that array is full, it should call a function to print the hex and text representations for the characters.

Fine. So read the file character by character. When the array is full, call the function. When the function returns, continue reading.

The fuction also needs to write the hex representation and, if the char is a special whitespace char (tab, new line, backspace, vertical tab, form feed, or any other non-printing char), it should call a function to print the escape sequence.

Makes sense. Test each character and output the hex if appropriate. If not, pass that character to this function.

So how do I even create an array? Or store things in it? Or use it to call a function?

Here's where you need to read your book. It's very basic.

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

All you need to do is read the character and output the same value in hex format. There are no calculations necessary.

This could all be horribly wrong because I have taken a lot of this from different forums and webpages all over the web. If anyone has any help, any changes, whatever, I would be glad to hear it!

The biggest problem with this technique is trying to mish-mash many different ideas together without understanding what they were doing.

I do the same as you as far as checking different sites for information. But they are only used as guides and information. Once I understand what they are explaining and how they help accomplish my task, I then write my own code because by then I understand the problem and the path to it's solution is clear.

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

Where did you

"Implement a separate function to reverse the order of the array using call by reference. The input of this function should be two pointers (pointing to original array and reverse array).

Without an attempt at this implementation, there's nothing to help with.

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

Yeah, so?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
>/*than it compares the two so:
>   0010100010001100100000000000
>                       10010110 |
>=  0010100010001100100010010110 
>*/

No.... Look up what a single | does.

>red = colour & 0xff
>
>/*than to get the last bits:
>      0010100010001100100010010110
>                          11111111 &
>                   red  = 10010110  

And a single &

And then word is then, not than ;o)

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

Yeah, especially when they probably can't...

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

FYI, it would be easier to tell if the value was loaded properly if you print using HEX (%X) instead of integer (%u). Food for thought.

I have tried to make a chart of how the unsigned int should look at the end, if its wrong than my understanding of bitwise operators is wrong aswell :P :

Print in both Hex and Decimal to compare, see if there is any truth to your assumption/understanding.

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

What do you mean? How can i do that?

Think. Reread your section on functions.

Just because you post a question here does not mean you can turn your brain off. You still have to figure many things out for yourself.

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

Print the program out
Grab another piece of paper and a pencil
Sit at your desk and go through the program line by line
Write down the variable names and what gets loaded into them
Follow the code until you see something that doesn't look right and figure out why.

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

Kind of. sizeof doesn't quite work that way. You want to pass the size into the function.

What does onefunction() do?

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

The exact same way you do there.

define funct(A1, size-of-array)
{
    define a2
    loop from 0 to size-of-array
        copy values
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You've never used a loop before?

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

Use a loop.

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

Not going to any pastebin. If you can waste the time loading onto pastebin, you can certainly take less time and copy/paste your info here.

Did you make changes to the code? Do we know what the code looks like now?

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

We certainly can try. I don't know about anyone else here, but
1) I can't see you screen from where I am so I don't know what you did wrong,
2) I don't know what you need help with because my psychic powers aren't working today.

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

So what are you comparing above?

I suggest you change your variable names to something worthwhile. result and result1 are not indicative of their use. resultPerson and resultComputer define closer what the values hold -- but you can still come up with better names. Many times that helps you 'see' what you are trying to do.

You have something you've called a "first roll". What would be a good name for that variable? Do you need the "first roll" more than once? Is it important to keep the "first roll" separate from subsequent rolls? Plan accordingly.

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

We know. That doesn't alter the fact that it's non-standard and should not be used.

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

can you pls show the codes? the finish one and it will run. cause we also have project like this and im having a hard time.

Don't do it. There's nothing worse than someone stealing your code for their homework.

joyce15, maybe you should ask some questions yourself -- in your own thread, of course.

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

Why bother with approximations? What is the purpose of inexactitude for this?

It's obvious.
1) It's part of the assignment to get the grade
2) It shows a possible approximation of the temperature conversion
3) Teaches how to calculate a percentage error via program

Many times there's more to an assignment than the mere calculation of a very simple formula. This is one such case. The percentage error is clearly the main purpos of this assignment.

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

You asked

So,please tell me how do I store value of the first roll and compare it with the next move(s).

I gave you a suggestion about how to do it. You responded with

@Waltp .. i am doing it here -

int result1 = compDice();
int result = userGame();

So what's the problem? Use those results and compare the subsequent rolls.

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

So,please tell me how do I store value of the first roll and compare it with the next move(s). I tried something, but it does not seem to work.

The same way to do it with any value -- create a variable to store the first roll and use that to compare all subsequent rolls.

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

error C2676: binary '+=' : 'IloNumVar' does not define this operator

Whatever IloNumVar is, you cannot do a +=. It's obviously not an integer.

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

@WaltP The way you showed me doesn't j++ so it would just keep replacing the same array

I wonder if there's a fix for that. I'm not going to do all your work. You still need to think. That's part of programming...

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

You have to be able to analyze the problem and pull out its important ideas. For example:

Issue: Your fellow students need help. This is their first year in college and

Who cares. Not part of the real problem...

they need to determine how many hours they need to study to get good grades.

Here is the problem statement. It's describes what needs to be done.

Study hours per week / Grade
5 / A
4 / B
3 / C
2 / D
0 / F

Here's the data necessary to determine the answer to the above question.

The user enters either the number of hours they plan on studying per week or the grade they want based on the number of creadit hours they enter.

The inputs required to process the data above.

The program displays the user's name, number of credits, total number of study hours, and grade they should expect to receive.

Additional inputs necessary for the output of the final solution have been added. Some is just bookkeeping (name). Some is the input for the solution (study hours or grade). The rest become the calculated values (grade or study hours) depending on the input.

In this case since there are 2 possible inputs (a letter for GRADE or a number for STUDY HOURS), there are two different calculations that need to be considered. Therefore a decision needs to be made …

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

1) indent better so we can read the code easier. 3 to 4 spaces is normal.
2) print your code and grab another piece of paper and a pencil.
3) sit at your desk and start at the top of your code and start writing out all the variables (including string sizes) and follow your code step by step, changing variables values and drawing the arrows to where the pointers point.

You should then see where you are going wrong and, if you can't figure out how to fix it, you can ask a really good question because you can explain in detail what you saw happening.

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

You can't read a string (%s) into a single char (name[i] and pid[i]). You need to define them both as 2D arrays,
names[Number of names][number of chars for each name]

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

I repeat:

What variables do you have to keep track of total wins and total losses?
Where in the code do you add a win/loss to the win or loss variable?
Where in the code do you need to output these totals?

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

Why don't you use the same technique i showed you for SPACEs, Numbers, and Punctuation? What I gave you was an example, not a complete answer. What if your 'sentence' is

Jonn Jonzz    2314 54th Street    High Plains, Mars --- out for lunch!!!
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What variables do you have to keep track of total wins and total losses?
Where in the code do you add a win/loss to the win or loss variable?
Where in the code do you need to output these totals?

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

I don't understand. You rememberd the number of wins and losses, therefore you saved them somewhere.

I think you need to explain in much more detail what you're confused about.

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

How about copying all of a type in one go:

    while (Block[i])
    {
        while (isalpha(Block[i]))
        {
            Token[j][k] = Block [i];
            k++;
            i++;
            Token[j][k] = '\0';  // be sure to 'end the string'
            Type[j] = 1;
        }

This will copy the entire word up to the first non-alpha character and leave you set at the following character.

A slightly cleaner option:

    while (Block[i])
    {
        if (isalpha(Block[i]))
        {
            k = 0;
            while (isalpha(Block[i]))
            {
                Token[j][k++] = Block [i++];
            }
            Token[j][k] = '\0';  // be sure to 'end the string'
            Type[j] = 1;
        }
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Refresh your cache...

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

Now you know why you should use variable names that make sense. Just choosing random letters obviously have drawbacks.

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

Is there a reason the user must enter 2 to roll? What's wrong with 1 or R? Or even ENTER? Better yet why can't the program just roll?

Let check the code. Doesn't the function compgame() actually roll the dice? So...

{
    compGame();                 // roll the dice once.
    userGame();

    if (compGame() == 7 || compGame() == 11)
    {                           // Dice rolled 2 more times
        cout <<"Computer won" << endl;
        value = false;
    }
    else if (compGame() == 2)   // dice rolled another time
    {
        cout << "Computer lost" << endl;
        value = false;

How many times is one player supposed to roll the dice in his turn? I count 4 for player comp... He cheats! :o)
Looks like you need to rethink the game play.

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

1) you can't use strcpy(). You are dealing with substring and this function is for full strings.
2) look up the functions I mentioned. They will make your life easier. Unless, of course, you like to string 15 conditionals inside 1 IF statement.

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

Let me see if I understand this.

Player 1 rolls the dice.
-- If he win (7/11) game ends.
-- If he looses (2) game ends.
If neither, Player 2 rolls.
They just keep passing the dice after one roll.
Is that about it?

Some current problems:
1) srand() can only be called once and expect it to work correctly. Move it to the beginning of main()
2) Never NEVER NEVER call main(). Use a loop to repeat the code.
3) If the user enters the wrong input, don't call the function (that's recursion -- look it up if you care). Just use a loop to ask again.
4) In dice() you roll the dice but never do anything with them. The values are lost. Don't you want to return the total value?
5) You don't need global values for die1 & die2.

That should hold you for a while. There's more to do, but let's see how far you get with this...