heey guys.. i have this h.w.. i solved the first part which is based on the second part.. but not sure whether i did it right or not.. can someone check plz..

this is the Q.. i only did the first part!

First create a one dimensional array called numbers that contains the following data
(Initialize the array with the numbers listed below).
6,7,-3,-4,5,-5,10
Output the array data to a file called data.txt.
==============================================
Then:
1) Calculate how many items are there in the file.
2) Calculates the number of the positive numbers and negative numbers
3) Calculate the sum of the positive numbers only.
4) Get a target from the user to search for; e.g. 7 (as an input from the screen)
5) Sort the array’s elements in ascending order and follow exactly the file snapshot next page.
6) Then append the result of 1) to 5) to the same file.

==============================================
now i created the input file and added the numbers to it.. but after running the program.. the numbers didn't appear in the output file.. dunnu why.. is smthn wrong with my code?

#include <iostream>
#include <cstdlib>
#include <fstream>

using namespace std;

int main ()
{

	int NUMBERS [7] = {6,7,-3,-4,5,-5,10};

	//declare file:
	ifstream read_in;
	ofstream data_out;

	//initialize file:
	read_in.open ("read_data.txt");
	data_out.open ("data.txt");

	//check file:

	if (data_out.fail())
	cout<<"Exit data";
	if (read_in.fail())
	cout<<"Exit read_data";


	//use file:

	for (int i=0;i>=6;i++)
	{
	read_in>>NUMBERS [i];
	data_out<<NUMBERS [i];
	}

	//close file:
	read_in.close();
	data_out.close ();






return 0;

}

Firstly from the question arent you supposed to read from "data.txt" and not "read_data.txt"

Secondly. I am quiet confused with your code.

You should first post all the Numbers into the file and then read in from the file again to perform math calculations ?

i dunnu.. i did from both.. but didn't work..
Is something wrong with my code?? i don't know

Let's start from the real code...
See for loop condition: i >= 6 . In other words, while i is greater than or equal to 6. The initial i value is 0...

This code confuses me . I donot understand whether read_data.txt has numbers in it or According to the problem statement. The file must be filled.

i filled th file read_data first and no output was shown in the data file.. it's mistake i know.. then i deleted what i filled and filled data instead.. but nothing appeared in read_data :S

i filled th file read_data first and no output was shown in the data file.. it's mistake i know.. then i deleted what i filled and filled data instead.. but nothing appeared in read_data :S

You wrote nothing to the read_data file!!! Read my previous post again!

This article has been dead for over six months. Start a new discussion instead.