Question
i need to fix this error i need to figure out how to make the program not count the same numbers (there are two 12's
i need to fix this error
i need to figure out how to make the program not count the same numbers (there are two 12's in the array and now the program sees it as two different nums)
=-----
#include
#include
#include
using namespace std;
/**
* A boolean function to validate whether a number is in range 0 to 110 or not
*/
bool validateNumber(double num)
{
if(num 110)
{
return false;
}
return true;
}
/**
* Function to read the file and assign the number read to the variable num as reference
*/
int readFile(ifstream &inF, double &num)
{
inF >> num;
if(!validateNumber(num))
return -1;
else if(validateNumber(num))
return 1;
else
return 0;
}
/**
* Function to write the read invalid numbers to the output file
*/
void write2File(ofstream &outF, double invalidNum)
{
outF
}
// main function
int main(void)
{
string filename;
ifstream inF;
cin >> filename; // reading the input file name from user
// opening the input file
inF.open(filename.c_str());
if(!inF) // checking whether the input file was opened or not
{
cout
return -1;
}
// opening the output file
ofstream outF;
outF.open("invalid-numbers.txt");
int validNumbersCount = 0;
int invalidNumbersCount = 0;
int totalNumbersCount = 0;
double validNumbersSum = 0;
cout
outF
while(!inF.eof()) // looping untill end of file
{
double num;
int returnVal = readFile(inF, num);
if(returnVal == -1)
{
invalidNumbersCount++;
write2File(outF, num);
}
else if(returnVal == 1)
{
validNumbersCount++;
validNumbersSum += num;
}
totalNumbersCount++;
}
// closing the files
inF.close();
outF.close();
double avg = validNumbersSum / validNumbersCount;
cout
cout
cout
if(validNumbersCount > 0) // if valid numbers count is greater than 0 then print average
{
cout
}
else // else print the error message
cout
}
zy 5.18. Ldb Lesson 9 (Par x 1 e Search Textbook Solutior x ? secure https://learn.zybooks.com/zybook/UTDALLASCS 11 36Spring2018LabB/Chapter/5/section/18 . ::: Apps D Payments ? Exar'' P: Probabilily! -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