66 926
Assignments Done
99,1%
Successfully Done
In October 2018

Answer to Question #1318 in C++ for ahmed

Question #1318
Write a program to read an input file of numbers and print all the count of positive numbers to one file and count of all negative number in another file.
Expert's answer
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
ifstream fin("data.txt");
int num_positive=0, num_negative=0, number=0;
while (!fin.eof())
{
& number=0;
& fin>>number;
& if(number<0) num_negative++;
& if(number>0) num_positive++;
}
fin.close();
ofstream fout1("positive.txt");
fout1<<num_positive;
fout1.close();
ofstream fout2("negative.txt");
fout2<<num_negative;
fout2.close();
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions