CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Dec 2009
    Posts
    6

    Help me plz with c++

    NEED HELP WITH THIS PROGRAMME ANY1 PLZ HELP AND GIVE ME ANY SOLUTIONS. PROBLEM IS BELOW

     Find out about Benford’s Law.
     Write a program which includes a function which takes two input parameters – the first being a digit, and the second being a sample size. The function should return the number of times Benford’s Law says this digit should occur in that sample size – so for example, if Benford’s Law says that 12.7% of a set of numbers should have the initial digit 6, and the two parameters are 6 and 400, the function should return the value 51 (12.7% of 400, rounded to the nearest integer).
     The program should ask the user to input a sample size, and call the function for each of the digits 1-9, displaying a table of the expected occurrences for each digit.
     Sample output:
    Input sample size: 700
    1 211
    2 123
    3 87
    4 68
    5 55
    6 47
    7 41
    8 36
    9 32

  2. #2
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Help me plz with c++

    Have you attempted to answer the questions?

    Viggy

  3. #3
    Join Date
    Dec 2009
    Posts
    6

    Re: Help me plz with c++

    yes i have i have the following

    #include <stdio.h>
    #include <math.h>


    float benfords_law(float, float);
    float samplesize;

    int main (void)
    {
    printf("Input sample size: ");
    scanf("%f", &samplesize);

    int i;
    for (i=1; i<=9; i++)

    printf ("i = %2d\n", i);



    float benfords_law(float integer, float size)
    {
    return (size*log10(1.0+(1.0/integer)));
    }

    system("pause");
    return 0;
    }

  4. #4
    Join Date
    Apr 2008
    Posts
    725

    Re: Help me plz with c++

    you can't define functions inside another function.

    #include <iostream> and then you can use cout, and cin steams that are much nicer than printf / scanf

  5. #5
    Join Date
    Dec 2009
    Posts
    6

    Re: Help me plz with c++

    we havent gone that far yet and supposely it suppose to be done in way tht i think im missing a line tht will solve it.

  6. #6
    Join Date
    Apr 2008
    Posts
    725

    Re: Help me plz with c++

    yeah, implement the benfords_law function outside of main(), and then call it several times from a loop

  7. #7
    Join Date
    Dec 2009
    Posts
    6

    Re: Help me plz with c++

    hw would u do tht ,so hw would the program luk like?

  8. #8
    Join Date
    Apr 2008
    Posts
    725

    Re: Help me plz with c++

    And what does that mean in English?

  9. #9
    Join Date
    Dec 2009
    Posts
    6

    Re: Help me plz with c++

    you have said implement benford law but how do u write that out ?

  10. #10
    Join Date
    Apr 2008
    Posts
    725

    Re: Help me plz with c++

    you've already written it, but it's inside main(){...}, which is not legal c++

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured