Hello, I have a program I am writing to count the number of integers (as well as the individual digits) in a file. I feel I'm close but I'm not quite there so any insight would be helpful.

I'll only post the segments of code relevant to where I need help.

My main function:

do
	{
		text.get(ch);

		if(isdigit(ch))
		{	
			sum = Integers(ch, count3, text);
			numofint++;
		}
	} while(!text.eof());

Integers function:

int Integers(char &ch, int &counter, ifstream& text)
{
	int total = 0;
	int sum = 0;
	bool success = true;
	
	while((isdigit(text.peek()) == success))
	{
		counter++;
		total = (total*10) + (static_cast<int>(ch)-48);
		sum += total;
	}	
	return sum;
}

Sorry, I should add the only libraries I am able to use are:
#include <iostream>
#include <iomanip>
#include <cctype>
#include <fstream>

and ... Whats the problem

The function is not returning any results. My counter inside it is set up to count the digits, but is continually returning the 0 is was initialized to, so I assumed the part that was wrong is:

while(isdigit(text.peek()) == success)

note: text is my input file stream.

However, I am not sure why or what to do differently since I've tried this many ways with no success.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.