Question
Writer a Program that tests Benford's Law. Collect a list of at least 100 numbers from some real-life data source and enter them inter a
Writer a Program that tests Benford's Law. Collect a list of at least 100 numbers from some real-life data source and enter them inter a text file. Your program should loop through the list of numbers and count how many times 1 is the first digit, 2 is the first digit, etc. For each digit output the perent it appears as the first digit. If you read a number into the string variable named strNum then you can access the first digit as a char by using strNum[0]. This is described in more detail in chapter 9 summary of bugs: Nothing is getting encoded to numtimes. Strnum[0] is not locating the first digit of a number. #include #include #include using namespace std; int main () { fstream inputStream; inputStream.open("100list.txt"); string Strnum; int numtimes[9] = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0} ; int total = 0; int i = 0; double percent; while(inputStream >> Strnum) { //go through every character in file. cout
Given the proper and complete answer
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started