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

lack of cleanliness

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

gooney

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

Basically, you have to turn the description into a set of quations. This has nothing to do with C++, yet.

2. A government research lab has concluded that an artificial sweetener commonly used in diet soda will cause death in laboratory mice. A friend of yours is desperate to lose weight but cannot give up soda. Your friend wants to know how much diet soda it is possible to drink without dying as a result. Write a program to supply the answer. The input to the program is the amount of artificial sweetener needed to kill a mouse, the weight of the mouse, and the weight of the dieter. To ensure the safety of your friend, be sure the program requests the weight at which the dieter will stop dieting, rather than the dieter’s current weight. Assume that diet soda contains one-tenth of 1% artificial sweetener. Use a variable declaration with the modifier const to give a name to this fraction. You may want to express the percentage as the double value 0.001.

Given the inputs described above, these ratios are useful and equivalent: SweetenerFriend / WeightFriend = SweetenerMouse / WeightMouse We know 3 of the 4 items, so rewrite as: SweetenerFriend = (SweetenerMouse / WeightMouse) * WeightFriend This gives you the amount of sweetener that will kill your friend.

Last thing to calculate is amount of soda. Since sweetener is 0.1% of the soda (or 0.001), you need to figure out how much soda is needed to get …

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

Over hill, over dale, we will hunt the rusty quail.

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

necessary because clean

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

came from somewhere

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

gonad

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

$35? Nowadays you can get domains for $10 or less...

Yeah, I know that. But $10 doesn't sound as stupid as $35 (the full retail price). Anyway, I get mine for $8.50

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

Such as? Do you have a question? Or are we supposed to figure out what you can't do psychically?

Be specific, ask questions. What do you want help with.

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

the demons within

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

antennae with a

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

shore

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

Onward and Upward

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

www.something.com

$35 a year down the drain....

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

I missed 4 & 5. Although I didn't think about 5 long enough. The rest were fairly obvious.

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

It would be one thing if this were a change which helped guests and hurt all regular members. But, based on this thread at least, you're the only one who doesn't love the new format.

I'm not in love with it either, but I do see some merit in it. I also like to know absolute times at times. (Dept of Redundancy Dept :))

In the edit note, the stamp says something like "Edited 3 minutes ago at 9:15", so give us both! Just add "at [time]" after the new format. IOW, complete the change because both forms are useful.

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

Generate a random number from 0 thru 16777215 (hex FFFFFF) and load the background color property.

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

Nah store them as chars, I always do. ints are unsafe. If the user doesn't type in an int where the program expects an int, it crashes, whereas with chars you can't go wrong, if it's bad, you just discard the input and tell them to try again.

Believe me this is the easiest way.

Sorry, I can't believe you unless you give an example of the danger. This comment makes no sense, for the reason Infarction stated.

Or are you talking about scanf() vs. fgets() ? If so, please be clearer. Even I get confused with half an idea like that.

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

Each of what? There's 118 lines here. Be specific.

And use code tags, information is everywhere!!!

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

Also, in C your statement char *newline = strchr(string, '\n'); is technically an illegal statement.

It is defined before any executable statements in the code block, isn't it? :confused:

Ahhh, so it is. Got caught by a style issue.

You really need to cut down the commenting a bit -- its overwhelming.

With practice you will surely come to know when the documentation is getting out of hand -- your code is almost 50 % documentation and that too sprinkled throughout the code which makes it difficult to read the code.

Completely disagree! A better form, maybe, but it's refreshing to see commented code. The more comments the better -- as long as they are descriptive & to the point and not just rambling thoughts. And his comments help understanding, they aren't extraneous.

Also it would be better if you would write documentation in a format which could be used for auto generating documentation for the entire project. Read this.

Unless you have a system to actually read the code for the documentation, it's not necessary. In all my years in programming I've only used one once. Personally, I feel it's unnecessary unless your job requires it. Without the generator it's a waste of time.

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

Agreed (and I used the QR box :D)

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

First of all, what did you do to get the code to print with colors like you did?

And has anyone explained code formatting? Indentation is necessary to understand code.

The problem is you don't seem to know how to test for prime numbers.
You actually have to test the number to see if it's prime from 2 up to the number (shorter is possible, but not yet). You can't just test if it's divisible by 2 and 3. There's also 5, 7, 11, etc.

And after you test the value you increment the number you input, so if you entered 22 you end up testing 22, 23, 24, 25, ..., infinity.

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

I think one of the reasons authors of books about programming in C make heavily use of the function scanf() is that is readily available and easy to use for the new learner.

But it's so dang unsafe and persnickety! :confused:

That's all good and dandy, however when writers of this books get to the more advanced topics, they fail to remember to go back and say: "by the way, forget about using scanf().
It's a function with a lot of overhead, and full of "gotchas".

And that's why I'd like them to stop teaching it. ;)

I have been looking to make a function of my own that I can use instead of the scanf(), and include in a header of file.

I think, that thanks to you guys, I have a good try here. I intend to create another for reading ints, and reading floats.

What do you think?. Do you see a better way, perhaps?.

Great job! Offhand, the only thing I'd do differently is instead of

char *newline = strchr(string, '\n'); /* look for the "newline" character and set the pointer to it */
if(newline != NULL)

I'd use

int newline = strlen(string) - 1;
if (string[newline] == '\n')

I believe it's faster to get the length of a string than to search for a character, and the \n will always be the last character.

I don't like the way I have to pass as a parameter the size of …

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

I don't understand your question in post #3

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

You have to control the cursor which is not something that Standard C++ can do. This takes commands that are system and/or compiler defined. And they are optional so they might not be defined for your system.

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

I like that change -- now we can turn line numbers on and off as we please. Hope you keep this feature. :)

I think this will work. Can you tell how many line are in the code block? If so, could you please add the toggle to the top of the block also if the block is greater than, say, 30 lines? If not, just add the toggle to the top. Many times people post 2 or more (window) pages of code and if we see something we wish to comment on at the top, we have to scroll all the way down, then all the way back up. This would also delineate the block nicely.

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

Think its self explanatory on what its supposed to do, ....

It's only self explanatory if it's commented, therefore it's not. We have to figure it out... ;)

but i dont know how to return to main, because its being called from the function by the time it reaches the return value.

It's called from main() the first time, so the last return gets to main() For example:
call sequence starts
main: 1st call to power
1st power: 2nd call to power
2nd power: 3rd call to power
3rd power: 4th call to power
return sequence starts
4th power: returns to 3rd power
3rd power: returns to 2nd power
2nd power: returns to 1st power
1st power: returns to main

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

Heres some reputation your way for being so kind.:) :) :)

Agreed.... Thanks

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

i am doing project on company store management.i have created a login form which asks for userid and password.this userid & paswword will be stored in database in oracle.so when the user types his id and password and clicks ok button it will first check whether the id corresponds to that password if yes it will allow further forms.

#1) Read the 5th paragraph in
this section
of The Forum Rules

#2) What's with the bold? Read the 4th paragraph from above link

so can u tell me coding for this.

#3) Now Read the 3rd paragraph from above link

#4) Don't know about your language but in English there is a space between sentences. You aren't writing web addresses.

its urgent.

#5) To quote the old office wall decoration:
Poor planning on your part does not constitute an emergency on our part

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

wait, i'm out of time.. i'll finish this soonnnn,,, if you want to finish this, please do.. Godbless

Sure, I'll get right on it... :rolleyes:

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

FireFox1.5 into VEdit -- line numbers.
FireFox1.5 into Notepad -- line numbers
Firefox1.5 into Wordpad -- line numbers

IE7 into VEdit -- one line, no formatting
IE7 into Notepad -- one line, no formatting
IE7 into Wordpad -- no formatting

Opera9 -- seems to work.

I see no reason for line numbers either. I doubt it's worth the trouble to track down the solution. And it would be too presumptuous to require a specific browser.

It would also be beneficial IMO to put back the label "code" and the lines above and below the code. Don't have to change the code format, just the head and tail.

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

OK. So use the information from my post and think about how you'd have to do it.

Or read the link from Dave. Two possible ways to handle this.

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

Mr WaltP,
Well done, in the explanation you give of avoiding gets()

Thank you.

However, I put together the piece of code that you sugested, and I must be missing something or I did not understand the last portion of it, because is not working for me.

if (b2[strlen(b2)-1] == '\n')
    {   /* full input line read */
        b2[strlen(b2)-1] = '\0';  /* remove the new-line */
    }
    else
    {   /* parial input line read */
        b2[0] = 0;  /* empty the b2 buffer */ 
        do
        {   
            fgets(dummy, 50, stdin);
            strcat(b2, dummy);  /* Save input but be sure */
                            /* sure to test your buffer size */
        } while (dummy[strlen(dummy)-1] != '\n');
    }

What did I not get?. I know you're trying to clear the stdin buffer using a dummy array in the else statement, but why the array b2 needs to be set to 0, and then why you want to append to that whatever remains in the stdin?

For what you are trying to do, you probably don't want to zero b2 and load dummy into b2 . How many characters did you read into dummy ? What size is b2 ? Can all those characters fit?

Think about what you want to do if you enter "thisisalongstring"? Since b2 is only size 5, do you want to output
this
isal
ongs
trin
g

? If so, you don't want the else at all. Just loop back and you'll read the next …

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

Yes, unfortunately, ads after all the content is just silly because no one will see them. You stop scrolling when the page content stops.

Possibly true, but to be honest, I don't see them anyway. As tgeer alluded to, it's noise and I would ignore it. The only ads I really see are those obnoxious ones that flash and scroll. I don't read them, I just notice and cuss them out (and usually scroll them out of the window).

But my browser has never displayed the ads by the QR box anyway so, like AD, before I had a large gap above, now I have empty space next to the box.

I am going to run a test on the Quick Reply box. It is my hypothesis that moving the Quick Reply box will create a big surge in the number of posts.

Testing is good! And since you can undo anything that doesn't work for the site, try as many iterations as possible over time.

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

Code and quote boxes have been changed.

Yes they have. And I think I like it! Just have to get used to it without the code box.

I like having userinfo up top because it does make the posts have more width, and the fewer line breaks there are, the easier it is to read.

I agree. And since I use a window width of 2/3 screen width, it works out well. Any narrower and I'd probably have to increase to 3/4 or (ghod forbid) full screen, which I would prefer not to do.

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

By the way, how did you get the color in the code you posted?

By manually coloring it...

I was asking the poster because I can't believe everyone that has color tags is actually doing it himself... :confused:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
for(i = 0; i <26; i++) 
  {        
      int length;
      int j;
      length = ((count[i] * 80)/(float)394);
      for (j = 0; j < length; i++)
      {
          cout << "=" << endl;
      }

  return 0;
  }

}

the last part is where im dumbingly trying to add it to my output. all that gets prints out is = signs that seem to loop forever. any help would be great guys.

Look carefully at your 2 for loops... Do you see a mismatch of variables?

And is your return where you want it?

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

But I don't know how to read file "data.inp" line by line. I think I should use fgets, but seem that fgets is used for char.

Yes, use fgets() to read the line, then you can use sscanf() to convert the line into numbers.

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

Let's see. You've tried

  • Thread listing
  • Ads
  • Quick Box

Now we have

  • Thread listing
  • Quick Box + Ads

Maybe

  • Thread listing
  • Quick Box
  • Ads

might work -- it helps our usability, and keeps your ads.

It seems that you feel the ads must be mixed into the middle of the forum content. If that's a requirement, then my idea can't work.

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

I agree that this quick-reply is too small. And the background is now:

Please wrap code in code-block and inline code-block.

Here is php code: echo "Hello
Here is c code: printf("Foo\n");
Here is echo "code";

Please restore the larger box...

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

Basically, yes. But use the proper syntax for your if

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

Mr WaltP,
Even when I wrote that weak comment, I had the feeling that sooner than later you would tell me something about that fflush(stdin). :)
And I agree!. The problem is I still don't know how to read and check
the stdin correctly. I have been trying to understand it, but I'm not happy with the solution.

Well, you could click on the link I gave you... That might be a first step ;)

By the way, how did you get the color in the code you posted?

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

And chocolate sauce

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

like it or not, bugs are here to stay

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

I got lots of references on google using dos.h int86.

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

ohhh, I see, lol. That was pretty easy. Thanks for the help. One other question. I'm not sure I really understand a while loop.

#include <iostream>
using namespace std;
int main()
{
float g=0,m=0,a=0;
while(g>-1)
{
cout<<"Enter the gallons used (-1 to end): "<<endl;
cin>>g;
cout<<"Enter the miles driven: "<<endl;
cin>>m;
a=(m/g);
cout<<"The miles per gallon for this tank of gas was: "<<a<<endl;
} 
return 0;
}

Where I have while(g>-1) why do I have that and what does that exactly mean? I think that it means while g>-1 the loop will continue to run. If that's the case with my program I need to have a person enter their gas and miles driven a certain number of times then find the average of the total. So how would that work if it never ends? Thanks again for the all the help.

When you type in -1, the program should end. 0 would be a better value, especially when you are using floating point values. Plus, 0 gallons used is not useful. And if you want it to exit immediately, you have to test the value as soon as it is entered.


And in direct answer to your title:
read Paragraph 5 here
You need to format your code with spacing and indentation

#include <iostream>
using namespace std;
int main()
{    // start indenting -- 4 spaces or so
    float g=0, m=0, a=0;    // space things out
    while (g > -1)
    {
        cout …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Regarding color changes, threads used to look like this:

www.daniweb.com/techtalkforums/getdaily.html

And now threads look like this:

www.daniweb.com/techtalkforums/forum8.html

Which do yo like better?

I am mildly (very mildly) partial to the yellow format. Not enough to complain, just noting preference.

I've personally never understood the need to have the "last post" information. The only info I'm interested is whether or not there have been posts since my last visit -- which we've got. For me, the last post information is meaningless.

Like newbies never, ever, ever using code tags? Cheers.

The only thing I've ever been able to come up with is, based on post count after SUBMIT is clicked, display a short form of the rules, something like
Have you explained what you need fully?
Have you posted code with code tags?
etc

I can also see why this is not a good solution, too, but it does get the info to the poster that hasn't read any rules.

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

deployment wizard doesnt work on XP for vb5 therefore i dont think the VB4 one will

Then why do they put it in VB? It's always worked for me... :confused:

[edit]Oops, come to think of it, I've never tried it on XP. Just NT[/edit]

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

Hi guys just wondering can any1 help i have a project for collage
and vb6 is really not my thing yet

Its my firdt year in collage and im doing computer maintenance and repairs

Vb6 is apart of it and to me it doesn't make any sence to me
can anyone help:-|

Yes we can. :)

im doing VB6 at college too. i could send you some sample code if you want (all commented)

Commented code? Is that allowed? :twisted:

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

Nobody said to ignore it, just that there may be problems if you use it that way. ;)

Exactly. No one said eof() was bad. They just said while (!xx.eof()) is the wrong way to use it. That form won't work in most cases. You used it properly. The OP didn't.