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

Bad code posted for no apparent reason. Should this thread be deleted?

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

I don't see any errors. If you do, you might want to explain them.

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

Set up a while loop that finds the largest digit in num and creates sorted:

save num for later in numSave; set smallest to 10
Loop until num = 0
   get last digit (%)
   remove last digit (/)
   if digit > smallest, replace smallest

Now remove that digit:

copy numSave to num
zero numSave
loop until num = 0
   get last digit (%)
   remove last digit (/)
   if digit != smallest,  multipy numSave by 10 and add digit

Add smallest to sorted (properly).
If numSave != 0 Loop back to do this all again

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

Based on the information you've provided, the easiest "database" for your data is a standard text file. Each line in the file contains employee name, age, contact number in a fixed format, say
char name[20];
int age;
char contact[10];

Read the entire file into a structure array and process with your commands.

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

Two possibilities:

Find the '.' and remove it. Reverse the number. Add the '.' back in.

Reverse the value. If the '.' is not in the proper position, switch characters until it's in the correct position. I.E., If your number reversed is
52.1232 switch the dot giving
521.232 and switch again
5212.32 and output the value.

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

With what? We have no idea what you've done!

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

I am a lawyer and never programmed before...

Then you obviously know the importance of pre-planning before jumping into the fire.

IMO, if you've never programmed before, it might be worthwhile to pay someone since this is not a trivial program. And you could actually help a college student with his resume at the same time. N'est-ce pas?

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

Do not ask for code. We are not a coding service. We will help you fix your code.

If anyone posts a complete working solution for you, they are enabling cheaters.
If you use that code you are a cheater.

Read me

If you are going to quote the BoilerPlate, quote the entire thing. He has at least 4 issues that it touches on...

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

I went back and figured that out and saw that I needed to make it a + and not a - when I was using strlen(x1)+1

I repeat -- WHY?
Why do you now need to add a null after the null that's already there? That's what your + is doing.

Directly to the point: Why do you need to add the null at all?

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

I am just a little confused with the function prototype and how to get it to work.

void numToEnglish(unsigned int num, char english[]);

Since it makes sense to us, you need to explain what's confusing you. We are notoriously bad guessers.

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

30 minutes have passed so I could not edit my original. Sorry for the repost.

No need to apologize. We understand the forum limitations.

Hope this is more readable.

No, it's not.

It actually helps to read and understand the link given, not just make more stuff up.

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

Okay, I did that and they are being read properly. I think it has something to do with when I add the null character, and it is taking away that last letter and replacing it with a null one.

How do I properly add a null character?

What makes you think you have to add it? If you do a strlen() and it works, doesn't that mean there already is a null?

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

Have you designed the program yet, or are you just tossing code around to see it it works?

This is the type or program you need to plan before starting to code. Design a roadmap of what needs to happen
1) when you find a directory
2) when you start looking at the directory contents
3) when you reach the end of the directory
What is the interaction between all of these actions?

A good design will almost write the code itself. Then all you need to worry about is the syntax of the language.

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

Hey all,

I have a question how would I go about perform a comparion for two boxes. I would have to find the length, width, and height of both boxes and compare the volume of them to see which box would have be larger.

You've got the solution exactly...

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

Advice #1: Reformat so the code is readable. Your indenting makes the code unreadable. See this.

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

Try outputting the words immediately after you input them.

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

It's because when you enter Y or y aren't you also pressing [enter]? You are leaving the [enter] in the buffer for the next input statement. You need to clear your buffer. I leave that exercise for you to search out.

A couple problems, though:
Never call srand() inside your program. Call it only once at the beginning of main() . You are seeding the random generator, not growing a forest of generators :icon_wink:

If you check if 'y' or 'Y' is entered, what are the possible values for the else condition? Is there really a need to test if the value is not 'y' or 'Y'?

Why are you calling play_game() then you have 2 WHILE loops to catch the result? Call the play_game() function only inside one single WHILE loop and use your YES choice to exit that loop. Your program will be much smaller and easier to follow. And you won't need all that IF nonsense at the end of the loop since the WHILE acts as an IF anyway.

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

You will also find it easier if you fill out the tens array so you don't have to do any math to get the correct subscript:

char* tens[] = {"---", "ten", "twenty", "thirty", "forty", "fifty", "sixty",
			"seventy", "eighty", "ninety"};

Now when you get the tens digit 2 it maps directly to twenty.

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

@Schoil-R-LEA you can do it that way, and yes I've done it that way, but it doesn't really matter because it's pretty much the same as calling main,

No, it's not at all like calling main() because calling main() is wrong. This has been explained already so it's not at all the same.

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

If at first you don't succeed, do a statistical analysis to correct the results.

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

You may quote and reference Daniweb content, but you may not reproduce the content. The difference is that a quote is a relatively small part of an article written in your own words, and reproduction is a large scale copy/paste of our content with little or none of your own.

Actually, a paraphrase is "relatively small part of an article written in your own words". A quote is a relatively small part of an article taken verbatim.

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

Here comes captain douchebag thinking thread is someone asking another to write the code for them.

What the h--- are you talking about?

Your description claims everything was working. I commented on that. Nothing is working.

I then added comments in your code showing what was wrong with the code itself?
Where do you get the asinine idea I thought you were asking for us to write it for you? Please, explain how you got that impression? I need to know... Please.

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

So basically I'm a little bit confused. I believe the logic of my program is correct; file pointer is declared, and I do have a character to store my array, it reads the file, and counts all the words pending a space in front/between/etc. Basically the program should ask the used the used to input the name of the file they're scanning. The file opens and goes through the program and outputs a line that tells the user the # of words in the file that was inputted.

My problem has been compiling it.

How can it possibly do all that stuff you claim it does if the program doesn't even compile? The mind boggles! :icon_rolleyes:


Your code:

#include <stdio.h>
#include <string.h>

int main()
{
    int count = 0;
    char *doc;              // Where is the actual storage?  A pointer 
                            //   does not hold data, it holds a pointer
    FILE *inp;
    
    printf("Enter the file name: ");
    scanf("%s", doc);       // See the scanf() link below
    
    inp=fopen(doc, "r");    // Why are you opening the file with a char*? 
                            //   Aren't you supposed to use a FILE pointer?
    
    while((doc = fgetc(doc)) != EOF)    // You get a character and
                                        // 1) destroy your file pointer
                                        // 2) destroy your character pointer.
    {
        if (doc == ' ')     // doc is a pointer.  It can't be == to a character.
            count++;
    }

    fclose(doc);
    
    printf("%s contains %d words\n",doc,count);
    
    return 0;
}

scanf()

MrNo commented: Ever consider that someone has been learning this on the side for less than a week or two? -1
Eagletalon commented: Attempts to help people develop their skills themselves, accurate comments and assistance +3
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

1) Never use goto . Use a while loop instead.
2) Format your code properly. It's difficult to follow and mistakes are made with bad formatting.
3) Always call srand() once and only once, at the beginning of the program.
4) Never use system("cls"); while programming. It's hard to debug code and see what has happened when the screen clears. We recommend never using it because it's annoying to the user, but if you really need it, add it after the program is running -- not before.
5) Never use system("pause"); . Why call the operating system to pause a program when cin will do it, cin is part of the language, and it's portable.

ndeniche commented: Excellent tip on the clear screen +10
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Please format your code properly. It will help you in the long run, and we won't get confused by misreading the code.

"draw from a deck of cards" is a little ambiguous. In detail, exactly what does it do? What happens to the deck?

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

parameters are the same as well as the def. used the same data members through out the code so can't figure out why it isn't working and why its asking for pointers.

They are?
I see in the parameter list a single int. ( void PolyNom::setCoeff( int term, [B]int coeff[/B]) )
I see in the function an array being used ( coeff[ term ] )
They are not the same.

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

Does what you have work? When that works well, what do you want to add next?

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

Ahhh, 2nd page. Lack of info... sorry.

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

Are you supposed to
A) input 10 numbers and not output duplicates?
B) input numbers until 10 numbers are output?
It's not quite clear.


Another option to each of the above is to set an array of 101 integers (0 to 100).
Zero them all.
As you read in a number, test array[number]. If zero, print it. If not, it's a duplicate.
Add 1 to array[number].
Go back and read another number.

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

Please, guys (Schoil-R-LEA and kjcjk), stop writing the code for people. They need to figure it out, we should point the way, but not fix the code.

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

I'll try what WaltP said.. but I'll have to use dynamic memory in that case and we just mentioned a few things about pointers in class.

Why? Your analysis is faulty.

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

Please forget the good Captain's 2nd and 3rd explanations. Even I would find them confusing if I was trying to learn loops. Just concentrate on his first example.

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

hi guys i need help.

Really? I was wondering why you joined.

In fact it's an assignment.

Really? Why else would you have come here?

I'm fed up with this stuff.

Really? Why do we care? Get to the point...

This is my code.

And nice code it is. Indented nicely. Comments should probably be lined up with each other, but at least there are comments. And a line or two should be split onto multiple lines for readability.

has got many errors.

Really? I don't see any.
No compile errors listed so it can't be that.
No programming errors listed so it can't be that.
No run-time errors listed either.

And you get the prize for the most really's for the day....

actually it's just messy.

Oh, if that's all it is, make it less messy.

please provide me with me a code

Ahh, we get to the real question. You want us to do your homework for you. Got it.
The DaniWeb Homework Service is closed this week. Sorry. You're actually going to have to do it yourself, or actually ask us an intelligent question about your code and assignment.

I see a history here. Your previous post was:

Write a program that converts upper case to lower or lower case to upper, depending on the name it is invoked with, as found in argv[0].

Yet another "do my homework for me" question. The DHS must …

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

Do not change j inside your loop.

All you need to do in the inner j loop is:
1) Compare b with the current x value (you are doing this)
2) If less than, replace b with the current x value.
That's it.

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

Hi Guys. My doubts are related to Brute Force Attack but let me Tell you first that it has nothing to do with the Hacking/Cracking. So please dont block/remove my Post on this Forum. I want to study more about Brute Force Attack because it is in my Subject (i.e. E-Commerce). I want to create something to minimize the risk of Brute Force.
I have the Following Queries:

Q.1. How much time a Brute Force Attack will take to guess a password of 10 digits which includes alphabets,numbers & special characters ??

How many total characters? (n)
Compute the time to make 1 comparison. (c)
Compute the time to create the next value to compare. (t)
n*c*t*10*10

Q.2. If a single processor will only execute the Brute Force Attack then How much times its Speed will increase (forget about the OS instructions here) ??

If only one processor, how can the speed increase?

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

Make an array of 10 strings.
Put each line read into this array.
After you've read 10 lines, start overwriting the strings from string[0].

In other words:
read line 1 --> load string[0]
read line 2 --> load string[1]
read line 3 --> load string[2]
read line 4 --> load string[3]
read line 5 --> load string[4]
read line 6 --> load string[5]
read line 7 --> load string[6]
read line 8 --> load string[7]
read line 9 --> load string[8]
read line 10 --> load string[9]
read line 11 --> load string[0]
read line 12 --> load string[1]
etc...

To output, skip to the next string (the one after the last one written) and start writing all the strings in order.

But -- what happens if there are only 7 lines in the file? Yours to figure out.

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

You example and one of L7Sqr's example violates a very important part of your task, namely:

Ideally the data should be entered from the user using scanf (hence the int num within the function for a for loop)

Why try to load the data in a different way? Just concentrate on what you actually need to accomplish -- user input. Use his 1st example with your inputs.

Chances are you will still have problems using scanf() , but reading this series will help you fix them.

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

Look at line 275 and 278 as your errors mention. What's the definition of coeff from your parameter list, and how are you using it? Are they the same, or even similar?

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

There is not one error mentioned in the original post other than a vague "output doesn't look right". Without any details, what can we say?

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

Here is the detail of theCompiler's program

He's having a problem with the coding so maybe you can help him out by suggesting an approach or an algorithm to his problem

If theCompiler confirms your assumption, we can further help him, if he also explains what help he needs.

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

Major problems:
1) Randomize should be used when the program starts, not when you click your button.
2) Never use GOTO, it's unnecessary and in your case does nothing worthwhile.
3) In line 13, how can luckyno = arrayno(check) since arrayno(check) has no value?
4) And through whatever magic might make luckyno = arrayno(check) true, why would you want to start all over?

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

Neither do we since we didn't write it and don't know know what else you want to do with it.

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

My Problem Is That I Cannot Find What I'm looking For , When I'm Studying My Reference Which is C, Programming Language 2nd Edition....
It Cannot Answer All of Questions...So I Tried Here...

In my experience C, Programming Language 2nd Edition explains EXACTLY how a loop works. Any explanation we give will simply be repeating what you already read.

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

Error is on line 13

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

P.P.S. <rant>Why are you using a raw array in a C++ class? (Yeah, I see what the prof says to do, but it is, in my opinion, a very poor use of your time and the compiler.) Introductory C++ should make much use of the STL and all the built in C++ types until you get your feet under you about what it means to program....</rant>

Ahh, yet another "I know better than the instructor" rant. Of course you do. You've been at it longer and understand more concepts than the student that hasn't been taught 100% of the language yet. Until they get to STL, you can't expect them to use STL.

And it's better not to use the built in types until you know how to make them yourself. When you learn how they work, you can then use the easy version. Otherwise you can't program worth beans if you get into a language that doesn't magically define all your special data types.

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

Don't use Rich Text. Just read the fie in as normal text.

Read in as much of the file as you can.
Do your search.
Since you have most if not all of the file it's now a simple matter to back up 20 lines and start printing.

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

concatenate the two strings before calling system

PERFECT thanks a million

Gee, what was it I said? Oh yeah,

Concatenate "C:\\wmplayer.exe " and fname into a char* and use that variable.

:icon_rolleyes:

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

Concatenate "C:\\wmplayer.exe " and fname into a char* and use that variable.