Hi i have a project for my c++ class that has me stumped! The goal is to determine if numbers from an input file ("numbers.txt") are even, odd, or zeroes and to display them on the screen. The trick is that I cannot write the program using only main(), I have to use functions. This is what I have so far:
/************************************
* Function Header *
* Reads File *
************************************/
int readFile()
{
while (inputFile >> )
}
/************************************
* Function Header *
* Splits numbers into digits. *
************************************/
void splitDigits(int integer, int digitCount, int digit[])
{
for (int i = 0; i < digitCount; i++)
{
digit[i] = int(integer / pow(10., double(i)));
digit[i] = int(digit[i]) % 10;
}
}
void countDigits(int &isEven, int &isOdd, int &isZero, int digitCount, int digit[])
{
for (int i = 0; i < digitCount; i++)
{
if (digit[i] == 0)
{
isZero++;
}
else if (digit[i] % 2 == 0)
{
isEven++;
}
else
{
isOdd++;
}
}
}
/************************************
* Function Header *
* Determines if int is *
* even, odd, or zero. *
************************************
void determine()
{
}/
/************************************
* Function Header *
* Displays total number of odds, *
* evens, and zeroes in input file. *
************************************
void display()
{
/************************************
* Main *
************************************/
int main()
{
int integer;
openFile(); // Call function openFile
if (!inputFile)
{
cout << "Error opening file.\n";
exit(0);
}
int isZero = 0;
int isEven = 0;
int isOdd = 0;
int readFile(); // Call function readFile
{
}
// determine(); // Call function determine
// display(); // Call function display
closeFile(); // Call function closeFile
return 0;
}
Any feedback would be much appreciated. I'm new to programming and am just totally stumped in this "intro" class.
It is unspecified whether or not to count the number of digits, however, I think it is safe to assume so since there are no single '0's in the .txt file.
also, this still doesn't set the code in "determine()" form. I cannot just use 'bool'. That would get me a 0. Not that I'm not appreciative or anything, I'm very grateful for every ounce of information that comes my way but there are certain criteria that I must meet.
> It is unspecified whether or not to count the number of digits, however, I think it is safe to assume so
no, it is not safe to assume
read your assignment or ask for a clarification to determine if you need to classify numbers or their digits
those are two diffferent problems with different approach (for example, for digits may use a look up table)
> this still doesn't set the code in "determine()" form
¿what's the purpose of determine()?
¿what''s the purpose of display()?
I highly doubt their signatures as they require an extensive use of globals.