How to count occurences of a number and its most frequent pair in a text file?
-
Supposed I have a text file having the results of the 6/49 lottery in it: 49-05-13-42-18-45 43-24-36-16-39-22 32-48-05-18-34-29 13-14-07-41-48-39 47-05-17-13-37-49 06-23-34-21-46-37 06-42-13-40-11-37 39-44-40-21-32-20 17-26-38-43-01-02 How can I achieve the following output written to a text file with filename, "occurences.txt"? 49 - 2 times 49 paired with 13 - 2 times I don't have an exact idea but maybe the following pseudocode can help:
void main ()
{
int numbercout<<"CHARACTER \t\ How many times it appeared"<
How can I go about this? :-(
-
Supposed I have a text file having the results of the 6/49 lottery in it: 49-05-13-42-18-45 43-24-36-16-39-22 32-48-05-18-34-29 13-14-07-41-48-39 47-05-17-13-37-49 06-23-34-21-46-37 06-42-13-40-11-37 39-44-40-21-32-20 17-26-38-43-01-02 How can I achieve the following output written to a text file with filename, "occurences.txt"? 49 - 2 times 49 paired with 13 - 2 times I don't have an exact idea but maybe the following pseudocode can help:
void main ()
{
int numbercout<<"CHARACTER \t\ How many times it appeared"<
How can I go about this? :-(
You cannot use character types that contain more than one character, like
'49'
. The first thing you need to do is read all the input, split the items into separate fields and convert the numbers to integers. You can then count the individual values, and the sets just by counting through all the saved numbers. You do not need to count from 1 to 49, since some of those values will not be present. -
Supposed I have a text file having the results of the 6/49 lottery in it: 49-05-13-42-18-45 43-24-36-16-39-22 32-48-05-18-34-29 13-14-07-41-48-39 47-05-17-13-37-49 06-23-34-21-46-37 06-42-13-40-11-37 39-44-40-21-32-20 17-26-38-43-01-02 How can I achieve the following output written to a text file with filename, "occurences.txt"? 49 - 2 times 49 paired with 13 - 2 times I don't have an exact idea but maybe the following pseudocode can help:
void main ()
{
int numbercout<<"CHARACTER \t\ How many times it appeared"<
How can I go about this? :-(
In additoon to what Richard said, you seem to be having a very vague understanding of C/C++ programming. Before trying your hand on a moderately difficult problem, you should really start with a tutorial on C++ programming. There are plenty of good sites on the web for this, e.g. at C++ Language - C++ Tutorials[^] You should specifically focus on the first chapter, which covers pretty much everything you need for the program you asked about.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
-
Supposed I have a text file having the results of the 6/49 lottery in it: 49-05-13-42-18-45 43-24-36-16-39-22 32-48-05-18-34-29 13-14-07-41-48-39 47-05-17-13-37-49 06-23-34-21-46-37 06-42-13-40-11-37 39-44-40-21-32-20 17-26-38-43-01-02 How can I achieve the following output written to a text file with filename, "occurences.txt"? 49 - 2 times 49 paired with 13 - 2 times I don't have an exact idea but maybe the following pseudocode can help:
void main ()
{
int numbercout<<"CHARACTER \t\ How many times it appeared"<
How can I go about this? :-(
I'm sure there are many ways to skin this cat, but how about a loop that reads each line of the file into a
string
type, then callsstring::find()
for things like "49-" and "-49"? If one of those is found, then do something similar with the 13. Would that work?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles