-
December 11th, 2009, 05:26 PM
#1
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
-
December 11th, 2009, 05:31 PM
#2
Re: Help me plz with c++
Have you attempted to answer the questions?
Viggy
-
December 12th, 2009, 10:11 AM
#3
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;
}
-
December 12th, 2009, 11:21 AM
#4
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
-
December 12th, 2009, 03:33 PM
#5
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.
-
December 12th, 2009, 04:04 PM
#6
Re: Help me plz with c++
yeah, implement the benfords_law function outside of main(), and then call it several times from a loop
-
December 12th, 2009, 04:12 PM
#7
Re: Help me plz with c++
hw would u do tht ,so hw would the program luk like?
-
December 12th, 2009, 04:49 PM
#8
Re: Help me plz with c++
And what does that mean in English?
-
December 12th, 2009, 04:53 PM
#9
Re: Help me plz with c++
you have said implement benford law but how do u write that out ?
-
December 13th, 2009, 04:58 AM
#10
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|