Hello~! ...again..
I got some help from you guys a while ago with this same app because it wouldn't run on winxp. It runs fine now, but my brother is still telling me he cant get it to work right...so rather than go through all the trouble of trouble shooting(he lives 7 hours away) I figured I would just translate the thing to java.
I think that even if I make an applet, he will still have to have his java all fully updated and whatnot so to avoid even that trouble, I would like to make this is simple Java Script if possible.

I just wanted to ask you guys if it was practically doable to translate this app to Java Script, or a Java applet if need be, before I dive in and start learning the details of how to put this thing together. The C++ version inputs and outputs to text files, but I figured that I would just use a text BOX instead, and have it clear the box and put the new results in the same box.

anywho, here is the C++ code:

#include "stdafx.h"
#include <fstream>
#include <iostream>
using namespace std;
struct PAIR
{
	UINT num1, num2;
	UINT lastdrawn;
};
int _tmain(int argc, _TCHAR* argv[])
{
	UINT R[20];
	UINT pair_matrix[71][71];
	UINT day = 1;
	PAIR pairs[4900];
	ofstream fout;
	ifstream fin;

	cout << "Initializing.....";
	
	memset(&pair_matrix[0], 0, 71*71*sizeof(UINT));
	memset(&pairs, 0, 4900*sizeof(PAIR));

	cout << "Done" << endl;

	cout << "Opening results.txt.....";
	
	fin.open("results.txt");
	
	if(!fin.is_open())
	{
		cout << "Could not open results.txt. Exiting program..." << endl;
		system("pause");
		return 0;
	}

	cout << "Success" << endl;

	cout << "Scanning numbers.....";

	while (!fin.eof())
	{
		fin >> R[0];
		if(R[0] == 0) continue;

		fin >> R[1] >> R[2] >> R[3] >> R[4] >> R[5] >> R[6] >> R[7] >> R[8] >> R[9] >> R[10]
			>> R[11] >> R[12] >> R[13] >> R[14] >> R[15] >> R[16] >> R[17] >> R[18] >> R[19];

		for(int x = 0; x < 19; x++)
			for(int y = x+1; y < 20; y++)
				if(pair_matrix[R[x]][R[y]] == 0)
					pair_matrix[R[x]][R[y]] = day;
		day++;
	}

	cout << "Finished" << endl;

	cout << "Building pair list.....";

	fout.open("pairs.txt");
	for(int x = 1; x <= 69; x++)
	{
		for(int y = x+1; y <= 70; y++)
		{
			for(int p = 0; p < 4900; p++)
			{
				if(pair_matrix[x][y] > pairs[p].lastdrawn)
				{
					for(int b = 4900-1; b > p; b--)
					{
						pairs[b] = pairs[b-1];
					}
					pairs[p].lastdrawn = pair_matrix[x][y];
					pairs[p].num1 = x;
					pairs[p].num2 = y;
					break;
				}
			}
		}
	}
	fout << " |last drawn|    |pair|" << endl;
	for(int p = 4899; p >= 0; p--)
	{
		if(pairs[p].num1 != 0)
		{
			fout << "       " << pairs[p].lastdrawn << "        (" << pairs[p].num1 << ", " << pairs[p].num2 << ")" << endl;
		}
	}

	fout.close();
	fin.close();

	cout << "Finished." << endl << "Statistics were saved in pairs.txt" << endl;

	system("pause");
	return 1;
}

Thank again for any *pointers=)

You could probably do that in Java or Javascript, those two are very similar to C++, in fact Java practically is C++

I would suggest Java over javascript because it's a real application language, it's totally OOP (so is Javascript, but in a different way)

I'm guessing you know java, but if you don't look for a few good tutorials about it on google:
http://www.google.com/#hl=en&q=java+tutorial&aq=f&oq=&aqi=g10&fp=OzgK0dwM7rU

Like i said, java and javascript are very similar; Java has most of the features of C++, and their syntax is so alike :)

hope i helped :)

This post has nothing to do with the converting between those two, but with:
Bad coding practices!

  1. !fin.eof() Check out this.
  2. system("pause"); Check out this.
    You could use cin.get() as a replacement.
  3. return 1; Why would you want to return value 1 if your program has terminated correctly?
    Make it return 0;

:)

This post has nothing to do with the converting between those two, but with:

Funny....I thought the topic of a thread was usually decided by THE ONE WHO POSTED IT.

How can you, with such a technical hobby, be this ignorant?

I figured I would just translate the thing to java.

Put that in yer IDE and compile it :P

You could probably do that in Java or Javascript, those two are very similar to C++, in fact Java practically is C++

I would suggest Java over javascript because it's a real application language, it's totally OOP (so is Javascript, but in a different way)

I'm guessing you know java, but if you don't look for a few good tutorials about it on google:
http://www.google.com/#hl=en&q=java+tutorial&aq=f&oq=&aqi=g10&fp=OzgK0dwM7rU
Like i said, java and javascript are very similar; Java has most of the features of C++, and their syntax is so alike :)

java and javascript are not the same, the only thing they share is the c like syntax. Java and JavaScript are 2 completely different languages

java and javascript are not the same, the only thing they share is the c like syntax. Java and JavaScript are 2 completely different languages

I understand that, but but Java Script is built right into every browser..even the older ones, isn't it? I don't remember ever having to install anything extra to view a java script page, and thats why I would rather use Java Script if possible...but Is Java Script capable of reading through a list of numbers, storing, and looping through them like my CPP app does?

I understand that, but but Java Script is built right into every browser..even the older ones, isn't it? I don't remember ever having to install anything extra to view a java script page, and thats why I would rather use Java Script if possible...but Is Java Script capable of reading through a list of numbers, storing, and looping through them like my CPP app does?

Why wouldn't it be able to do that?
That are just the fundamentals of a language (though JavaScript is like the name says: a scripting language)
But: Keep one thing in mind: Because JavaScript is not compiled, others might be able to read your code.
(Though there are tricks to cloak your code a bit)

The reading of the file(s) might be a problem.

Isn't PHP a more suitable language for this?
(You'll have to keep in mind that PHP is a server-side language, which means that your programs run on the webserver, not on the user client's computer, so you'll have to host it on a webserver which supports PHP, there are plenty of free hosting providers who do).

Funny....I thought the topic of a thread was usually decided by THE ONE WHO POSTED IT.

How can you, with such a technical hobby, be this ignorant?

This isn't my fight, I'm positive tux4life can argue his own opinions but in the interest of fairness I figure I'd make a comment.

I think you misunderstood what he were saying, as from what I read he didn't decide to try to change thread topic or say your post had nothing to do with the topic, he were actually mentioning before-hand that his own post had nothing to do with what you asked. Implying he's instead interested in addressing the problems he saw within your code, whether or not you appreciate this isn't entirely relevant as such comments help everyone else who reads the thread, especially those who don't know & want to learn, without such posts this forum wouldn't be nearly as worth as much as it is.

I haven't said all that to preach at you or anyway, I'm aware that you could very well understand it, I went into detail for anyone else who might be reading who just didn't get it... For clarity-sake if you will. So anyway I think it were just a misunderstanding, atleast somewhere down the line, if you didn't misunderstand, I certainly did! :D

Comments
Exactly :) (Though I just ignored that post :P)

This isn't my fight

nuff said..

Yiuca
Junior Poster in Training

*rolls eyes*


TUX! thank you. I will look into the php thing. I don't need to write or read to any files. I think replacing the contents of a textbox with the processed information would suffice. It's good to know I have another option besides java applets to explore though if java script can't get it done.

Comments
If you can't show respect for anyone, don't post.

Dont give answers like this. why u r doing like tis.If u know the conversion then give it. other wise it is god to keep quiet.

> Dont give answers like this.
We're here to inform and educate, not spoon-feed answers on demand.
You TRY, we HELP - that's the deal.

This question has already been answered. Start a new discussion instead.