This is my code. It is a two Dimensional Array.
The program reads in 25 numbers from a data file then is supposted to sort them. All the code is simple, I used all the code in another program that does a one Dimensional Array. I am new to C++ so any help would be VERY VERYN Greatful.
The numbers are 1 thru 25 in random order
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
//Array used in this program.
int array[5][5];
int x;
int y;
int numin;
int temp;
//File read in and use.
fstream fin ("random numbers.txt");
for (x = 0; x < 5; x++)
for(y = 0; y < 5; y++)
{
fin >> numin;
array[x][y] = numin;
}
//Loop; sort array and print to screen
x = 0;
while (x < 5)
if (array[x][y] < array[x+1][y-1])
{
temp = array[x+1][y-1] ;
array[x+1][y-1] = array[x][y];
temp = array[x+1][y-1];
array[x][y] = temp;
}
else
{
x++; y++;
cout<<"["<<x<<"]" "["<<y<<"]" << " ";
cout << "\n";
}
//Write to a file.
fstream fout("sorted.txt");
fout <<" sorted: ";
return 0;
}