Help: why does it keep showing a wrong number?

This is a discussion on Help: why does it keep showing a wrong number? within the C Programming forums, part of the General Programming Boards category; I'm a beginner at C so I don't understand why my "False Positives" keep printing a large negative number? Am ...

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    4

    Help: why does it keep showing a wrong number?

    I'm a beginner at C so I don't understand why my "False Positives" keep printing a large negative number?
    Am I doing something wrong? Please help!

    Code:
    #include "stdio.h"
    
    float falsePositive (float accuracy, float incidence, int population);
    
    
    
    
    void question();
    
    
    int main() 
    {
        printf("QUESTION 1\n");    
        question();
    
    
        return 0;
    }
    
    
    
    
    void question() 
    {
    float accuracy, incidence;
    int population;
    
    
        printf ("Enter population size:");
        scanf ("%d", &population);
    
    
        printf ("Enter the accuracy of the test as a percentages (e.g. 99):");
        scanf ("%f", &accuracy);
    
    
        printf ("Enter the incidence of the disease as a decimal fraction (e.g. .0001):");
        scanf ("%f", &incidence);
    
    
        printf("Population = %d, accuracy = %.2f, incidence = %.5f, False Positives = %.0f\n", population, accuracy, incidence, falsePositive(accuracy, incidence, population));
    }
    
    
    
    
    float falsePositive (float accuracy, float incidence, int population)
    {
        float falsepositives, healthypeople;
        healthypeople = (population * (1-incidence)); 
        falsepositives = (healthypeople * (1-accuracy));
    
    
        return falsepositives;
    }

  2. #2
    Registered User
    Join Date
    Feb 2012
    Posts
    1
    this may b due to %.0f for falsepositive !!!
    try using %.1f

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    Are you sure you're inputting the right percentage?
    Code:
    $ ./a.out 
    QUESTION 1
    Enter population size:1000000
    Enter the accuracy of the test as a percentages (e.g. 99):.95
    Enter the incidence of the disease as a decimal fraction (e.g. .0001):.0001
    Population = 1000000, accuracy = 0.95, incidence = 0.00010, False Positives = 49995
    $ ./a.out 
    QUESTION 1
    Enter population size:1000000
    Enter the accuracy of the test as a percentages (e.g. 99):95
    Enter the incidence of the disease as a decimal fraction (e.g. .0001):0.0001
    Population = 1000000, accuracy = 95.00, incidence = 0.00010, False Positives = -93990600
    In other words, do you need to pre-divide your percentage by 100 to express it as a fraction between 0 and 1 ?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Feb 2012
    Posts
    4
    Ahh! Finally it works!! Thanks so much for your help, Salem!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to reprompt after user inputs wrong number?
    By gnozahs in forum C Programming
    Replies: 11
    Last Post: 10-03-2009, 04:49 PM
  2. Window not actually showing.
    By Shamino in forum Windows Programming
    Replies: 3
    Last Post: 02-22-2008, 10:55 AM
  3. number is showing as 2?
    By Corleone in forum C Programming
    Replies: 8
    Last Post: 11-12-2007, 10:12 PM
  4. structure not showing any value
    By sainideepak in forum Linux Programming
    Replies: 2
    Last Post: 02-28-2003, 11:25 PM
  5. Pic not showing up
    By Hunter2 in forum Game Programming
    Replies: 14
    Last Post: 11-13-2002, 01:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21