Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
0
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; }
17th Jul 2017, 7:29 AM
Diana Pîşlac
Diana Pîşlac - avatar