//I am having problem with the final portion of my program; it is for a class.
//This is what I have so far, and the exact instruction I have for final part are:
//Finally, modify the above program to read the numbers in from a text file (numbers.txt), write the values in reverse order to a second file, and read the words in from a third file, displaying the results to the Console as described above. This is your completed project.
//I am still working on this, but can you help me out? Not sure if I am going to be able to edit this code and figure it out on my own.

#include <iostream>
#include <string>

using namespace std;


int main()
{
	
	int array[5];
	int counter;
	string words[6];
	const string endWord("end_of_array");

	cout << "Please enter five numbers: ";


	for (counter = 0; counter < 5; counter++)
	{
		cin >> array[counter];
	}

	cout << endl;


	cout << "The numbers are: ";

	for(counter = 0; counter < 5;counter++)
	{
		cout << array[counter] << " ";
	}

	cout << endl;



	cout << "The numbers in reverse order are: ";

	for (counter = 4; counter >= 0; counter--)
	cout << array[counter] << " ";

	cout << endl;

	char trash[256];
	cin.getline(trash,256,'\n');
	
	
	cout << "Please enter five words: ";

	for (counter = 0; counter < 5; counter++)
	{
		cin >> words[counter];

	}
	words[5]=endWord;

	
	counter=0;
	cout << "Print out 1st and 3rd letter of each word: " << endl;

	do
	{
		cout <<  words[counter].substr(0,1);
		cout << words[counter].substr(2,1);
		cout << endl;
		counter++;

	}while( words[counter]!=endWord);

	
	return 0;
}

//I am missing this from the end, it wouldn't let me edit it again.

ifstream inData;
ofstream outData;

inData.open("numbers.txt");
outData.open("output.txt");

inData >> number;
inData >> counter;

outData << "Read five numbers " << number << endl;

inData.close();
outData.close();

return 0;
}

//I have moved a little forward, and this is what I have now(all I need to do is initialized the 5 words from txt file and have a console output):

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main()
{

int array[5];													//Initalize array
int counter;													//Initalize variable
string words[6];
const string endWord("end_of_array");

ifstream inData;
ofstream outData;

inData.open("numbers.txt");
outData.open("outData.txt");

for (counter = 0; counter < 5; counter++)
{
inData >> array[counter];
}						

for(counter = 4; counter >= 0;counter--)
{

outData << array[counter] << " ";
}

inData.close();
outData.close();

cout << "The numbers in reverse order are: ";					

for (counter = 4; counter >= 0; counter--)

cout << array[counter] << " ";

cout << endl;

char trash[256];

inData.getline(trash,256,'\n');

inData.open("words.txt");

for (counter = 0; counter < 5; counter++)
{

inData >> array[counter];

}

cout << "Print out 1st and 3rd letter of each word:\n" << endl;	

do
{
cout << words[counter].substr(0,1);
cout << words[counter].substr(2,1);
cout << endl;
counter++;
}

while(words[counter]!=endWord);

inData.open("numbers.txt");
inData.open("words.txt");
outData.open("outData.txt");

inData >> counter;
inData >> words[6];

outData << "Five numbers " << counter << endl;
outData << "Reverse numbers " << counter << endl;
outData << "Five words " << trash << endl;

inData.close();
outData.close();

return 0;
}
This article has been dead for over six months. Start a new discussion instead.