3 lines

we11er

Newbie
Joined
Jan 13, 2004
Messages
1,035
Reaction score
0
OK, I got excited the first time I realised there was a Coding forum, but unfortunately there isn't much activity here is there? I'm gonna try something here, which will likely turn out to be a crap idea, but we need some innovation anyway!

So here it is - I start with a basic C++ program. From there, you can add upto 3 lines of your own, and then someone else adds a further 3 lines, and we see what happens. You can do anything you want, perhaps turn it into a release-date calculator? Humour is highly recommended.

If you want to discuss modifying the rules that's fine - I'm writing this on the spurr of the moment, without even thinking about it. So, here we go:

Code:
#include <iostream>
using namespace std;

int main( int argc, char** argv )
{
    cout << "Welcome to the halflife2.net Coding forums's open-source SUPER program!" << endl;

}

So now someone adds some more lines. Hope this works. ;)
 
*char UserName;
cout << "Please identify yourself with a nick."
cin >> UserName;

theres my addition. altough i dont remeber if its correct c++ code.
lets see if someone else would participate.
 
*throws bugs at Chrysalid* NO! BAD CODER!! BAD!! BACK INTO YOUR ROOM!
for my 3 lines I'd like to replace Chrysalid's crash with
std::string UserName;
 
this sounds like a fun idea (and yay for someone else who laments this forum being a graveyard) but i really don't know what this thing should do..

also, i foresee some LONG lines of code creeping on if this catches on. (say, an in-line for loop with 30 instructions :p)

Edit: Oh, and, if anyone doesn't want to code and just has a great, (relatively) simple idea that they think would be cool, do tell! Nothing silly, we arn't going to re-create source or anything (or are we? :O ).

Also, howabout a rule that you only post a tagged full listing if you know it works (on at least your system), so people can differentiate coding errors and local compilation errors?
otherwise, i'd prefer having a lot of [ code ] tags then just snippets inside the message body...

just a suggestion.
 
oh, btw. neither works, for me. been too long since i worked with c++ much.

( from: )
std::string UserName;
cout << "Please identify yourself with a nick.";
cin >> UserName;
( is: )
main.cpp: error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
 
lol I knew someone will correct my terrible faults... Well actually i'm a C coder. Fun idea this is, anyway. Maybe someone should make a similar thread using Brain**** as the language. :D
 
oaky-doaky. added a <string> include, another cout, and replaced the cin with getline...
Code:
#include <string>
#include <iostream>
using namespace std;

int main( int argc, char** argv )
{
    cout << "Welcome to the halflife2.net Coding forums's open-source SUPER program!" << endl;
    std::string userName;
    cout << "Please identify yourself with a nick: ";
    getline(cin, userName);
    cout << "\nHi, " << userName << "!  Now, let's get Bizzae!" << endl;

}
Btw, this runs for me. All mine will prolly be MS VS .NET (VC++ 7.1) compiled... If anyone runs a different ver or Gcc or something, please tell and point out any incompatibility probs you see...

P.S. i suggest replacing <tab>'s with <space>'s, becuase the formatting might get wonky otherwise.
 
Time code???
note: rename vars if needed
Code:
#include <time.h>
.
.
.
tm          *cur_time;
time_t     long_time;
 
cin >> UserName;
works for me, the getline messes up when you execute it, I type my name, enter, wait .. nothing hapens. type enter again, ah! now it works!

may I use namespace std; ?

ok so here comes my changes:
I let the user put his name as a parameter
Code:
#include <string>
#include <iostream>
using namespace std;

int main( int argc, char** argv )
{
    cout << "Welcome to the halflife2.net Coding forums's open-source SUPER program!" << endl;
    
	string UserName;

	if (argc > 1)
	{
		cout << "\nI see, you already identified yourself.\n";
		cout << "Well Hi, " << argv[1] << "!  Now, let's get Bizzae!" << endl;
	}
	
	else
	{
		cout << "Please identify yourself with a nick: ";
		cin >> UserName;
		cout << "\nHi, " << UserName << "!  Now, let's get Bizzae!" << endl;
	}

	return 0;
}
 
technically that violates the 'add up to 3 lines' rule... they're not my rules though, we'll see what more people think?

I prefer the using 'getLine()' bacuase it can take a name with spaces in it, i.e. first & last. What compiler/os you using? just curious where the incompatability is.

Edit: Oh, well yes, the cin >> works for me also now.. I dunno why it idn't before.

to sage: okay, time. i haven't used that. what should we time??
 
techneically, I only added
if (argc > 1)
{
cout << "\nI see, you already identified yourself.\n";
cout << "Well Hi, " << argv[1] << "! Now, let's get Bizzae!" << endl;
}
which is three lines, :p

hmm .. time, maybe time how fast he types his name? if he's teh fast then he's teh leet.

edit:
oh, I'm using MSVC++ 6
 
He wanted it to become a release countdown timer
 
Ooh, exciting.

Here it is for you non-geeks. Remember to view it in the command line or it'll close before you see the last lines. Unless someone wants to add an extra cin...
 
Just a quick re-write
Code:
#include <iostream>
#include <time.h>

using namespace std;

int main( int argc, char** argv )
{
	char		UserName[30];
	tm			*cur_time;
	time_t		long_time;

    cout << "Welcome to the halflife2.net Coding forums's open-source SUPER program!" << endl;

	if (argc > 1)
	{
		cout << "\nI see, you already identified yourself.\n";
		cout << "Well Hi, " << argv[1] << "!  Now, let's get Bizzae!" << endl;
	}
	else
	{
		cout << "\nPlease identify yourself with a nick: ";
		cin.getline(UserName, 30, '\n');
		cout << "\nHi, " << UserName << "!  Now, let's get Bizzae!" << endl;
	}

	// Release date not yet confimed. Dont get angry or anything... 11/26/04 0:0:00
	// 365 - 36 = 330th day of the year
	time(&long_time);
	cur_time = localtime(&long_time);

	// int yLeft = 2004 - (cur_time->tm_year + 1900);
	// int mLeft = 11 - cur_time->tm_mon;
	int dLeft = 330 - cur_time->tm_yday;

	cout << "Days left till Half-Life2's release: " << dLeft << endl; 

	return 0;
}
 
sage said:
He wanted it to become a release countdown timer
oh.
duh.

I've heard MS VC++ 6 is a fair bit short of ANSI compliant... That must be it.
As an example, IIRC, in a 'for' loop started in VC6 with:

for (int i=0; i<5; i++)

the 'i' will not pass out of scope with the end of the loop. I HATE that.

Edit:
You could add a line:
System("pause");

This may be dos/win only, i dunno.
 
Make it alittle easier..

Code:
#include <iostream>
#include <time.h>
#include <conio.h>
#include <stdio.h>

using namespace std;

int main( int argc, char** argv )
{
	char		UserName[30];
	tm			*cur_time;
	time_t		long_time;

    start:
    cout << "Welcome to the halflife2.net Coding forums's open-source SUPER program!" << endl;

	if (argc > 1)
	{
		cout << "\nI see, you already identified yourself.\n";
		cout << "Well Hi, " << argv[1] << "!  Now, let's get Bizzae!" << endl;
	}
	else
	{
		cout << "\nPlease identify yourself with a nick: ";
		cin.getline(UserName, 30, '\n');
		cout << "\nHi, " << UserName << "!  Now, let's get Bizzae!" << endl;
	}

	// Release date not yet confimed. Dont get angry or anything... 11/26/04 0:0:00
	// 365 - 36 = 330th day of the year
	time(&long_time);
	cur_time = localtime(&long_time);

	// int yLeft = 2004 - (cur_time->tm_year + 1900);
	// int mLeft = 11 - cur_time->tm_mon;
	int restart, dLeft = 330 - cur_time->tm_yday;

	cout << "Days left till Half-Life2's release: " << dLeft << endl;
    getch();
}
 
untill there is a firm release date, I suggest leting the user input a date in a std::String format, and have a function parse it :p dd/mm/yy
print the number of seconds remaining until that day, assume the usualy steam update time, what is it, 7 PST?
 
Phisionary said:
what is with the 'restart' var and that 'start:' tag there?
Well, that would be a case of me doing to many things at one time >_<
Should be:
(hope there aren't any more things I left in there)
Code:
#include <iostream>
#include <time.h>
#include <conio.h>
#include <stdio.h>

using namespace std;

int main( int argc, char** argv )
{
	char		UserName[30];
	tm			*cur_time;
	time_t		long_time;

        cout << "Welcome to the halflife2.net Coding forums's open-source SUPER program!" << endl;

	if (argc > 1)
	{
		cout << "\nI see, you already identified yourself.\n";
		cout << "Well Hi, " << argv[1] << "!  Now, let's get Bizzae!" << endl;
	}
	else
	{
		cout << "\nPlease identify yourself with a nick: ";
		cin.getline(UserName, 30, '\n');
		cout << "\nHi, " << UserName << "!  Now, let's get Bizzae!" << endl;
	}

	// Release date not yet confimed. Dont get angry or anything... 11/26/04 0:0:00
	// 365 - 36 = 330th day of the year
	time(&long_time);
	cur_time = localtime(&long_time);

	// int yLeft = 2004 - (cur_time->tm_year + 1900);
	// int mLeft = 11 - cur_time->tm_mon;
	int dLeft = 330 - cur_time->tm_yday;

	cout << "Days left till Half-Life2's release: " << dLeft << endl;
        getch();
}
 
small addition:
Code:
#include <iostream>
#include <time.h>
#include <conio.h>
#include <stdio.h>
using namespace std;

int main( int argc, char** argv )
{
	char UserName[30];
	tm* cur_time;
	time_t long_time;

	cout << "Welcome to the halflife2.net Coding forums's open-source SUPER program!" << endl;

	if (argc > 1)
	{
		cout << "\nI see, you already identified yourself.\n";
		cout << "Well hi, " << argv[1] << "!  Now, let's get Bizzae!" << endl;
	}
	else
	{
		cout << "\nPlease identify yourself with a nick: ";
		cin.getline(UserName, 30, '\n');
		cout << "\nHi, " << UserName << "!  Now, let's get Bizzae!" << endl;
	}

	// Release date not yet confimed. Dont get angry or anything... 11/26/04 0:0:00
	// 365 - 36 = 330th day of the year
	time(&long_time);
	cur_time = localtime(&long_time);

	// int yLeft = 2004 - (cur_time->tm_year + 1900);
	// int mLeft = 11 - cur_time->tm_mon;
	int dLeft = 330 - cur_time->tm_yday;

	cout << "Days left till Half-Life2's release: " << dLeft << endl;

	int guessMatch = (cur_time->tm_sec)%10, guess;
	cout << "Wasn't that fun?  Let's play a game, shall we?  Guess a number between zero and nine to quit: ";
	do {
		guess = (int)getch()-48;
	} while (guess != guessMatch);

}
Edit: Suggestion: Remove the 3 line limitation... Theres a lot of cool things you can't do within three lines..
Maybe -- only one feature addition at a time?
 
Added who did whats...
more to come..

Code:
#include <iostream>
#include <time.h>
#include <conio.h>
#include <stdio.h>
using namespace std;

int main( int argc, char** argv )
{
	char UserName[30];
	tm* cur_time;
	time_t long_time;

	// part 1 - we11er
	cout << "Welcome to the halflife2.net Coding forums's open-source SUPER program!" << endl;
	
	// part 2 - hasan 
	if (argc > 1)
	{
		// part 2 - Chrysalid/Phisionary/others
		cout << "\nI see, you already identified yourself.\n";
		cout << "Well hi, " << argv[1] << "!  Now, let's get Bizzae!" << endl;
	}
	else
	{
		// part 2 cont. - Chrysalid/Phisionary/others
		cout << "\nPlease identify yourself with a nick: ";
		cin.getline(UserName, 30, '\n');
		cout << "\nHi, " << UserName << "!  Now, let's get Bizzae!" << endl;
	}

	// part 4 - sage
	// Release date not yet confimed. Dont get angry or anything... 11/26/04 0:0:00
	// 365 - 36 = 330th day of the year
	time(&long_time);
	cur_time = localtime(&long_time);

	// int yLeft = 2004 - (cur_time->tm_year + 1900);
	// int mLeft = 11 - cur_time->tm_mon;
	int dLeft = 330 - cur_time->tm_yday;

	cout << "Days left till Half-Life2's release: " << dLeft << endl;

	// part 5 - Phisionary
	int guessMatch = (cur_time->tm_sec)%10, guess;
	cout << "Wasn't that fun?  Let's play a game, shall we?  Guess a number between zero and nine to quit: ";
	do {
		guess = (int)getch()-48;
	} while (guess != guessMatch);

	// how int he hell did we forget this???
	return 0;
}
 
Suggestion: Remove the 3 line limitation... Theres a lot of cool things you can't do within three lines..
Maybe -- only one feature addition at a time?
Agreed.
You guys agree? Any objections? none? ok. :D


Code:
#include <iostream>
#include <time.h>
#include <conio.h>
#include <stdio.h>
using namespace std;

// part of part 6 - hasan
struct Date
{
	int dd; int mm; int yy;
};


int main( int argc, char** argv )
{
	char UserName[30];
	tm* cur_time;
	time_t long_time;

	// part 1 - we11er
	cout << "Welcome to the halflife2.net Coding forums's open-source SUPER program!" << endl;
	
	// part 3 - hasan 
	if (argc > 1)
	{
		// part 2 - Chrysalid/Phisionary/others
		cout << "\nI see, you already identified yourself.\n";
		cout << "Well hi, " << argv[1] << "!  Now, let's get Bizzae!" << endl;
	}
	else
	{
		// part 2 cont. - Chrysalid/Phisionary/others
		cout << "\nPlease identify yourself with a nick: ";
		cin.getline(UserName, 30, '\n');
		cout << "\nHi, " << UserName << "!  Now, let's get Bizzae!" << endl;
	}

	// part 4 - sage
	// Release date not yet confimed. Dont get angry or anything... 11/26/04 0:0:00
	// 365 - 36 = 330th day of the year
	time(&long_time);
	cur_time = localtime(&long_time);

	// int yLeft = 2004 - (cur_time->tm_year + 1900);
	// int mLeft = 11 - cur_time->tm_mon;
	int dLeft = 330 - cur_time->tm_yday;

	cout << "Days left till Half-Life2's release: " << dLeft << endl;

	// part 5 - Phisionary
	int guessMatch = (cur_time->tm_sec)%10, guess;
	cout << "Wasn't that fun?  Let's play a game, shall we?  Guess a number between zero and nine to quit: ";
	do {
		guess = (int)getch()-48;
	} while (guess != guessMatch);

	// part 6 - Hasan
	cout << "\n\nOk, enough with the guessing. Tell me, when do you tink HL2 will be released?\n";
	cout << "Enter your expected date in dd/mm/yy format\n";
	
	Date rdate;
	char x;

	cin >> rdate.dd >> x >> rdate.mm >> x >> rdate.yy;

	//do something with the date structure? - hasan


	// how int he hell did we forget this??? - sage
	return 0;
}
 
Im dieing to find the whole date/time count down thing out. Feel Free to finish/rewrite my part! :cheers:



Code:
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <time.h>

using namespace std;

// part of part 6 - hasan
struct Date
{
	int dd; int mm; int yy;
};


int main( int argc, char** argv )
{
	char UserName[30];
	tm* cur_time;
	time_t long_time;

	// part 1 - we11er
	cout << "Welcome to the halflife2.net Coding forums's open-source SUPER program!" << endl;
	
	// part 3 - hasan 
	if (argc > 1)
	{
		// part 2 - Chrysalid/Phisionary/others
		cout << "\nI see, you already identified yourself.\n";
		cout << "Well hi, " << argv[1] << "!  Now, let's get Bizzae!" << endl;
	}
	else
	{
		// part 2 cont. - Chrysalid/Phisionary/others
		cout << "\nPlease identify yourself with a nick: ";
		cin.getline(UserName, 30, '\n');
		cout << "\nHi, " << UserName << "!  Now, let's get Bizzae!" << endl;
	}

	// part 4 - sage
	// Release date not yet confimed. Dont get angry or anything... 11/26/04 0:0:00
	// 365 - 36 = 330th day of the year
	time(&long_time);
	cur_time = localtime(&long_time);

	// int yLeft = 2004 - (cur_time->tm_year + 1900);
	// int mLeft = 11 - cur_time->tm_mon;
	int dLeft = 330 - cur_time->tm_yday;

	cout << "Estimated days left till Half-Life2's release: " << dLeft << "\nHuzzahh!!!" << endl;

	// part 5 - Phisionary
	int guessMatch = (cur_time->tm_sec)%10, guess;
	cout << "Wasn't that fun?  Let's play a game, shall we?  Guess a number between zero and nine to quit: ";
	do {
		guess = (int)getch()-48;
	} while (guess != guessMatch);

	// part 6 - Hasan
	cout << "\n\nOk, enough with the guessing. Tell me, when do you tink HL2 will be released?\n";
	cout << "Enter your expected date in mm/dd/yy format\n";
	
	Date rdate;
	char x;
	
	// note: mm/dd/yyyy | Sorry, im american.. =P - sage
	cin >> rdate.mm >> x >> rdate.dd >> x >> rdate.yy;

	// part 7 - sage *WIP* Im stumped about what to do with days.. hard code?
	// anyhow remeber that months should be figured by day not year..
	// also time should play a factor. **Note: Feel free to finish this part!

	/* Date tdate;

	cout << "\nExcellent, now lets figure up the remaining time..." << endl;
	
	time(&long_time);
	cur_time = localtime(&long_time);
	
	tdate.mm = (rdate.mm + ((rdate.yy - 4) * 12)) - cur_time->tm_mon;
	tdate.dd = 0;
	tdate.yy = rdate.yy - 4;

	cout << tdate.mm << " Month(s) " << tdate.dd << " Day(s) " << " and " << tdate.yy << " Years!" << endl; */
	return 0;
}
 
hmm .. I'm writing a function to do it ..
Code:
int CountDays(Date date1, Date date2)
{
	int days = 0;	//this will count

	//fist count based on years, then count based on remaining monthes, then 
	//based on remaining days. we have to keep track of what type of year this is
	// err .. if year % 4 == 0 where Feb has 29 days, what do you call it?

	int curr_year;
	int years_diff, month_diff, days_diff;

	//get the number of "integer" years .. 1 and half year is just one year.
	years_diff = date2.yy - date1.yy;
	if (date2.mm < date1.mm)
	{
		years_diff--;
	}
	if (date2.mm == date1.mm)
	{
		if (date2.dd < date1.dd)
		{
			years_diff--;
		}
	}

	if(years_diff != 0)
	{
		for(int y = date1.yy; y <= date1.yy + years_diff; y++)
		{
			if(y % 4)
				days += 366;
			else
				days += 365;

		}
	}

	//to be continued

	/*
	.
	.
	.	add stuff here
	.
	*/

	return days;
}
My algorithm goes like this ..
Find the number of "whole" years betwen the two dates, and calculate the days in those years.
Now there will be some months remaining (remainder), count days for them as well, then account for the reaming days ..

I did the first part, if anyone wana continue feel free, if you know a better way to do it also feel free.

I also precalculated the number of days for each month.
Code:
//pre calculate days per month
const int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
//month 0 doesn't count, when feb is 29 we just use days[2] + 1;
P.S. can you declare a const int [] like that? I never tried it but don't see why it shouldn't be ok.
 
I figured we would need to "hard code" it. Ill check it out.
 
hasan said:
P.S. can you declare a const int [] like that? I never tried it but don't see why it shouldn't be ok.
why wouldn't you be able to? btw, you don't need to put the array size in there, that will be set automatically...

Edit: shit, I did a leap year calculator in my cs class with java... I coulda ported it.. but i lost (had stolen...) my usb key with it on it. darn...
 
hmm.. doublepost eck...

I think i will write a date class. There probably already is one that I cound use or inherit but I know very little of C++ class libraries..

so, unless someone is almost completely done with a working system, I'll make a settable date class with a compare() ((Edit: or heck, operator overloading! I miss that when using Java :D)) method. Nothing like writing classes that will never be reused for anything :E

We should think up some other things to do with this proggy... so, anyone not involved in coding at the moment, do some quick brainstorming and come up with something cool, eh?
 
Cool, this seems to have worked. It gets us talking about standards and stuff!

Yeah, scrap the 3 lines thing.

There's gonna be a problem with the code getting too big isn't there? Probably the best thing is to just post the section that is being worked on at the time as people seem to be doing - you can keep a local copy of the full program for youreslf.
 
Oh yeah, since this is C++, you really shouldn't have the .h's at the end of the include files!

So it's just

Code:
#include <stdio>
#include <conio>
#include <time>

Although I think Microsoft doesn't like this - so if anyone has a problem then we'll keep it the same.
 
I think the .h suffix is replaces with a c prefix. eg <ctime>
 
no, <ctime> would be the C-style header, no namespaces etc.
 
I guess we are the onyl ones here .. let's come up with some new ideas while the date thing is being implemented (btw, anyone working on the date?)

hmm .. let's see.

/me brain storms ..

.
.
.


hmm .. nope, my head is empteh. :bonce:
 
I was going to work on a date...
...but I stopped :rolling:

right now I'm trying to make a menu.

You know, so we can pick between the one function our program has :E
 
We could turn it into a text-adventure game. But that would be alot of code, which wouldn't work. In fact, nothing much is going to work!
 
we don't have to put the code inline in our posts. could just post major changes and attach it as a txt file.
 
Should we scrap our current code and start a thread for a txt rpg?
 
I don't particularily like text rpgs =P
 
If we are going to write something... make it a challange...a time calculator proggy isn't the most difficult thing...

make it worth our time...

I really can't think of anything though...
 
lol this is the problem - we can code, but can't think up an idea to save our lives! Always the same....
 
Back
Top