Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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)

=-----

image text in transcribed

#include

#include // to input / output files

#include // for setprecision()

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! - ?? ? zyBooks y lbxrary CS 1135 home 1 Lsb Lesson9 Part 2 ot 2 ez,000ks catalog @repro ? Hijnsen CrS 4: Compare outputA Output differs. See highlights below. Input ni.Lx Rosaing Ezea fi1"uera2.tut or output vlad valu Re 01?? tron ile "nurrersz.txt.' Expected outut Iovalid vales 0/5 cope ouiput Output differs. See highlights below. Input nuricers txt Reading fron f:l "nunhersa.txt" Your output Ilis sle Iotsl values 6: Compare output A 1:14 PM Type here to search 4/15/2018

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago