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.
1
Expert's answer
2011-01-13T14:44:49-0500
#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 the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS