Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Also, if you want the user to enter one 4-digit number you don't have to put each digit in an array, unless you need each digit for something else. If you just want one integer, this is a quick way of doing it (without error checking)

int num = 0;
for(i=0;i<4;i++)
{
 a=getch();
 printf("*");
  num = (num * 10) + a - '0';
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

check the login account of that service program -- it may not have permissions to do that. Also service programs do not have a console, so it might be waiting for someone to press the <Ok> button in a message box which can not be displayed.

I don't see the purpose of launching installation programs from a service program anyway. I know I would not want a service program automatically installing something on my computer without my explicit instructions to do so.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>How do i convert the string character into a number?
you don't need sscanf() -- just subtract '0' from the ascii digit. Make sure the ascii char is a numeric digit before conversion.

char a = '1';
int num;
if( isdigit(a) )
   num = a - '0';
else
   num = 0;

>>for(i=0;i<4;i++)
what happens if I type 5 digits, or 100 digits? or a a bunch of random keys? Don't expect peope to do what you tell them to in the printf() statement.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

So is the consensus to keep C and C++ together for now?

Yes, I think it should remain as it is. I haven't seen anyone confused with this.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Oh sorry, Ancient Dragon! My solution has way too much fluff; your method is much better.

Nevermind my bloated-and-overly-complicated code solution. ;)

You had a good solution too. Don't discount the power of multiple suggestions.:)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

post your code -- I lost my binoculars the other day so I can't see your computer screen. :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

i need help with this part

I posted the answer to one half. Just copy it into the other half and make appropriate changes to the less-than-operator. I know you can do it if you think about it a few minutes. If you have been racking your brain several hours, then go watch TV or do something else for awhile.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Take this thread as an example. I want to comment about it on this board instead of hijacking the original thread.

How do all those obnoxious color codes get inserted into such posts? It looks like they were created by some other program then pasted into the post. That is not the only thread I have seen like that. As a moderator I don't have the time to edit out all that crap and insert proper, acceptable code tags.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Not to mention some newbies start mixing together C and C++, which would only make a moderator's duty even harder... :D

I sometimes do that myself, and I've been programming for 20 years:eek: There are some c++ constructs that I just do not like, so I toss C functions into the mix. I'll use efficient fprintf() when I need fairly complex formatting because c++ streams are difficult, cumbersome and obnoxious.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The easiest sort algorithm to code is the bubble sort. Just google for it and you will find hundreds of code examples.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

post your code so we can help you. We are not here to help you cheat at school.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That's a good reason to initialize all pointers to NULL as soon as possible so that you can check their validity before attempting to free them. I believe that free() will do nothing if you send it a NULL pointer.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

OMG! where did all those color codes in your post come from?? Did you enter all that crap manually? Or did your editor do that?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you need to add two more counters -- total number of morons and another counter to indicate whether the last guess was higher or lower.
For example:

else if (nNum>nGuess)
{
    if( last_guess < nGuess )
    {
          cout << "moron";
          moronCoujnt++;
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You might get the source code for this open-source accounting package to see how they do it. I have not seen it so I don't know if it will help you or not.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

if you find it in another language then just port it to assembly. I suspect that may be easier said than done,. but will give you the basic algorithms. Sorry, I can't help you more.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why would you want to write a program that advanced in a programming language you said you know nothing about? Learn the language first.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't know what that program is, but google seems to have a fair amount of information

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

This is one of those touchy subjects we'd rather not discuss. Thread closed.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you can create a structure that contains the x, y, color and shape, then have a vector of those structs.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I got 90% -- guess I can still drive in my old-age :mrgreen:

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

sometimes you can not win if you put them on the Aces too soon -- might have to take some back off.

I read somewhere that the third game you play is always winable. So, after starting the game select menu item Game-->Deal twice.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't understand the question -- do you want to kill other programs with your VB program? Can you explain in more detail what you want , or give examples?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

don't know about VB but here's a c solution

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Thanks dear Ancient Dragon for your nice comment; you said that you work hard,, then if we work hard it means it has some benefits, either for us or for someone else..

Adding comments in your code can not be under-emphasized. Programs need comments that explain what it is doing. If readers do not know what the program is supposed to do then they will most likely not take the time to read and understand it. You yourself will forget within three months, I know because I've been there and done that. Comments become even more important than the code itself to improve code maintenance; at some future time someone other than yourself might have to change it. And if you get a job writing code you will be required by your employer to well-document your code.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

there are hundreds of them -- just use google. Here are the ones from Microsoft

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Patches are frequently applied in machine code. NASA's procurement process for Space Shuttle flight software had the vendor providing a "signed off" image. Subsequent fixes after image sign off were applied as machine code patches. I had 20 words of patch space to work with in the Shuttle's SP0 cockpit display processor. Split 8 here and 12 over there. A reassemply/recertification of the load image to collect them up together was too economically painful to think about. We did hex patches.

You proved my second reason (obscure os) -- not many people have the opportunity to program for a space shuttle. :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Really? I was getting fond of system functions. What do u mean by OS api functions? Can u give me an example. Like for Dev C++, i m using the system("cls") command for clearing the console, what shud i use to replace that?

Lets say you want a list of all the files in a directory. One way to do that is system("dir *.txt > file.lst") which will put the list in a file named file.lst. Although that is convient because it doesn't require much coding, a much better way is to use os-api functions, such as win32 api function FindFirstFile() or *nix function opendir(). You will find examples of both these functions in the code snippets board. You will also find a lot of other nice-to-know stuff there also.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

most programmers frown on using system function for anything but quick-and-dirty little programs that you intend to give to no one. There are almost always C or C++ functions, possibly os api functions, that will do the same thing, often with a little more coding.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

True, but always writing malloc calls in this form p = malloc ( number * sizeof *p ); will ensure that the scaling for the size of object being allocated will always be correct.

http://c-faq.com/malloc/sizeofchar.html

from your own link

It's never necessary to multiply by sizeof(char), since sizeof(char) is, by definition, exactly 1.

p = malloc ( number * sizeof(char) ); is the same thing as p = malloc ( number * 1 ); which is identical to p = malloc ( number ); . So why bother with the extra typing :eek: and extra reading :eek:

One problem (I know you are aware of this but others may not) with using malloc(), of course, is that when the value of number is positive and greater than the maximum value that can be stored in size_t, which will happen only if sizeof(int) is not the same as sizeof(long). Or when the value of number is a negative signed int, in that case the value actually passed to malloc() may be unpredictable and probably undefined.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

BCD as I understand it is encoded in a series of bytes, the number of bytes depends on the desired level of precision and maximum desired number of digits. The value of Bill Gates net worth (64 billion the last time I saw it) (64,000,000,000) which would require 6 bytes (11/2) for packed BCD (two digits per byte). I don't know if this is still used in accounting systems or not.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

put a break point at the beginning of the function and step through the program one line at a time to see where it breaks. Also check the validity of all pointers -- If a pointer has a value something like "hchchchchc" that is what the compiler initializes them to when compiled for debug -- and is an uninitialized or bad pointer.

And please stop creating a new thread every time you have a new question about the same program. Just post your question(s) to the existing thread, that will bump it to the top of the list.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It happens occasionally for me too, but its not limited to DaniWeb, I've seen it elsewhere also and assumed its just the way the internet works some times.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is a free math library that allows (nearly) unlimited precision. I know there are others too.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

the errors you posted are not of much value. You should compile your program for debug then step through it one line at a time until you find the place where it crashes.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That fixed it. Thanks

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Mel, have you tried upgrading to the latest version of Firefox (2.0.0.1)? Perhaps it's just a Firefox bug that's gotten fixed in the next generation of Firefox.
.

Just checked -- there are no newer updates for XP

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

When I use firefox version 1.5.09 I can not copy the highlighted text within code tags to the clipboard. But in IE6/7 I have no problem. Is this a DaniWeb problem or Firefox? I only experience the problem on my home computer, where I use Firefox most of the time, except when I want to copy posted programs.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I just discovered this, and will gladly donate the cpu time of my computer to this worthwhile team effort.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I still don't see how that example will gaurantee 2 decimal places if there is less than that in the original input
doubles always have a lot of decimal places regardless of how they are rounded. If you using printf() you will see that

double a = 1.23F;
printf("%.6f\n",a);

Output of above will be 1.230000 (6 decimal places). You should not be concerned about just 1 decimal place because internally the double will always have quite a few (actual number will vary with the integer part of the number). If the number is large enough you might get something like this: 1528.535047 × 102 -- which is scientific notation.

Here is a pretty good explaination

Use this to output 2 decimals even if rounded to one cout << setfill('0') << left << setw(4) << a ;

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

sizeof(char) is not necessary because is it guarenteed by standard to be 1.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you might want to add some debugging print statements in some of those functions to see if they are writing beyond the boundries of the allocate memory for those arrays. For example, does loc_x + wd*loc_y exceed the allocation limits of the array?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First place to start is installing the device driver, I suppose you might get one from the camera's manufacturer. Google will give you some information also.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I have been testing ~S.O.S~'s example and it seems to work pretty well with the values I tested. Just a small change to the program (VC++ 6.0 doesn't like const initialized inside the class). But it works (rounds to 2 decimal places) with both positive and negative values. Don't know if it will work with ALL possible values though.

// WARNING: Untested
#include <iostream>
#include <cstring>
#include <sstream>
#include <cmath>

static const double PRECISION = 100 ;

 
class MyDouble
{
    public:
        MyDouble( ): var_(0.0) { } ;
 
        MyDouble( double var )
        {
            double int_part;
            var = var * PRECISION ;
            double fract_part = modf(var, &int_part);
            if(fract_part < 0)
            {
                if( fract_part < -0.5F)
                var--;
            }
            else
            {
                if( fract_part > 0.5F)
                    var++;

            }
            var = static_cast<int> ( var ) / PRECISION ;
            var_ = var ;
        }
 
        friend std::ostream& operator << (std::ostream& ostr, MyDouble& obj )
        {
            ostr << obj.var_ ;
            return ostr ;
        }
 
    private:
 
        double var_ ;
} ;
 
int main( )
{
    using namespace std;
 
    MyDouble a( 7.311 ) ;
    cout << a ;
 
    cin.get( ) ;
    return EXIT_SUCCESS ;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I want to have a variable that is born as rounded to 2 decimal digits,processed as rounded to 2 decimal digits and finally posted to MS SQL as rounded to 2 decimal digits.

Isn't that what he wants.. ?

No, I don't think so.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I guess his last two points would take care of that one....

only on output -- internal representation of the double will not change. No matter how you slice it a double is still a double regardless of setprecision. The only way to get around the internal representation problem is to not use doubles at all.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It appears you are the only one complaining about them, I have not seen any complaints from anyone else. Is your video card really ancient and supports only 64 colors so that your monitor does not support different shades of grey?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't mind an ad on the screen. I do mind ads which do the following:

- Drive you crazy with flashing, motion, or jittering.
- Won't let you leave the page.
- Won't let the rest of the page load until you read the entire ad sequence once.
- Change the position of the screen scrolling to bring the ad back into view.
- Keep the browser downloading more ads (some people still have to pay for the amount of web traffic, or lose their connection after so much traffic has passed).
- Change the display of another page by changing the available screen size.

I wish that the ad people would realize that the people they annoy WON'T WANT TO BUY THE PRODUCT.
.

I agree -- in fact I make it a point to NEVER visit that site again. Put it on my blacklist. I have never ever see that sort of advertising on DaniWeb.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Would it suffice to declare MyDouble as a wrapper class to type double?

Probably not because such a class still has all the properties of double data type. You would need a class that does not depend on either float or double if you always want an exact precision. doubles and floats can not give that to you.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you can't consistently do that with doubles or floats. I have never used MATHLIB so I don't know if it will do what you want or not, but you can research it.