Lowest price ever! Learn Generative AI for 48% less!
Get my discount0
This should work, but you need to make those 3 files. I commented and explained my code:
#include <iostream>
#include <fstream> //the file library
using namespace std;
ifstream x("LAB1.TXT"); //input file called through x;
ofstream y("LAB1EVENS.TXT"); //y for evens output
ofstream z("LAB1ODDS.TXT"); //z for odds
int main()
{
int a;
while (x >> a) //we read LAB1 through x and put the values in a;
{
if (a % 2 == 0)
y << a << " "; //evens are outputed in y;
else z << a << " "; //and odds in z;
}
return 0;
}