HELP WITH CODE!!

\
Last edited on
I can give you some tips and hints to get you started.

So first, I would get the value from file, store it as a string, and check if first character (the first number) is the digit you're looking for or not.

1
2
3
4
5
6
7
8
9
10
11
ifstream inputFile;
inputFile.open("data.txt");

string number; 
int counter1;                   // this value will hold the count for the values whose first digit is 1
inputFile >> number;     // get the number from file and store its value into string number
while (!inputFile.eof())   // loop  until the end of file
if (number[0] == "1")   // if first digit of number (index 0) equals 1, increment counter1
{
   counter1 += 1;
}



Now what you need to do, is do the same if-else thing to check if first digit equals 2,3,4 etc...
Hint: You'll need to use an another loop (probably a for-loop) to do that

Hope this helps!
Topic archived. No new replies allowed.