Thread: compare input doubles

  1. #1
    Registered User brianptodd's Avatar
    Join Date
    Oct 2002
    Posts
    66

    compare input doubles

    I am trying to write a program that accepts an undetermined amount of doubles as input and compares those values and determines a high, low and an average. I am using -1 as a sentinel for end of input.

    Attached is the code I have so far. It is not setting the minimum value and the average always includes the -1 as a value. I have compensated for the -1 in my average calculation by adding and subtracting 1.

    Any help is appreciated.

    Brian

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Well, you were checking for -1 too late, for one. Second, the comparison against max doesn't affect min. Consider that. Also, if the user enters 100 for the lowest number, the min will remain 0!
    Finally, the -1 shouldn't find it's way into the calculations. If you were using an array, for instance, you would simply stop calculating/iterating once you reached the sentinal.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User brianptodd's Avatar
    Join Date
    Oct 2002
    Posts
    66

    still problems

    I looked at the code you sent and compiled and ran it. It works fine if the numbers are entered descending, however, if the user enters 1,2,3,4,5 as the values, the output for the minimum is 1e+07, or 10,000,000 as it is declared. The value for min doesn't get reset to the lowest value.

    Brian

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Just give it a go. Mentally trace through the program with acending input.

    If you see the mistake I made, let me know about it.
    Otherwise, if you know what printf() does, let me know.

    It's a riddle!
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I would love some input on my BST tree.
    By StevenGarcia in forum C++ Programming
    Replies: 4
    Last Post: 01-15-2007, 01:22 AM
  2. Replies: 16
    Last Post: 01-04-2007, 03:38 PM
  3. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  4. Custom Made Safe Input Function
    By Beast() in forum C Programming
    Replies: 6
    Last Post: 08-21-2004, 10:19 PM
  5. need help with some input
    By blindleaf in forum C Programming
    Replies: 2
    Last Post: 03-16-2003, 01:50 PM