Go Back   Forums > Community Chatterbox > Tech Corner > Programming
Memberlist Forum Rules Today's Posts
Search Forums:
Click here to use Advanced Search

Reply
 
Thread Tools Display Modes
Old 03-03-2005, 03:14 AM   #21
YMIHere
Newbie

 
Join Date: Oct 2004
Location: ,
Posts: 7
Default

Sweet! I should come here more often so I can learn C/C++ with some of you guys. =)

Anyway, my first game was a guessing game that let you pick the range, but I accidentally overwrote it when trying out someone elses guessing game. I gave someone the source, but when I asked for it back they were busy. Haven't seen him in months. =P

Since that one's out of the question, I also made a cheesy little eight-ball program. =)
Code:
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

int main()
{
	char choice='y';
	printf("\n\nHello, I'm am the almighty eight-ball. You should know what to do \
 *with me by now so start with the questions.\n\n");
	while(choice=='y'||choice=='Y')
	{
 *int random_number;
 *while(getchar()!='\n');
 *srand((unsigned)time(NULL));
 *random_number=rand()%9; *//Limit the random number from 0 to 10.
 *switch(random_number)
 *{
 *	case 1:
 * *printf("All signs point to yes.\n");
 * *break;
 *	case 2:
 * *printf("Not very likely.\n");
 * *break;
 *	case 3:
 * *printf("Of course.\n");
 * *break;
 *	case 4:
 * *printf("It looks a bit murky, maybe money will help me see the answer.\n");
 * *break;
 *	case 5:
 * *printf("What the hell are you asking me for?\n");
 * *break; *	
 *	case 6:
 * *printf("Go away, fool!\n");
 * *break;
 *	case 7:
 * *printf("The answer is 42, it's always 42.\n");
 * *break;
 *	case 8:
 * *printf("Do I bother you while you're sleeping? Maybe I should.\n");
 * *break;
 *	case 9:
 * *printf("How the hell should I know? I'm a freaking ball.\n");
 * *break;
 *	default:
 * *printf("No.\n");
 *}
 *for(int i=0;i<300000000;i++);	//Pre-historic sleeping operation.
 *printf("\nWould you like to ask another question?(y/n)");
 *choice=getchar();
 *if(choice=='y'||choice=='Y')
 *{
 *	printf("Ask away.\n\n");
 *}
 *fflush(stdin);
	}
	return 0;
}
Now for anyone who wants to look at some really ugly stuff, I made a text Yahtzee game a while ago, but it's kind of big so I'll add it as an attachment. I don't understand much of it any more so I can't explain why I did certain things, but I do know that I was taking numbers from players as text because if they entered text when I wanted a number Yahtzee would freeze up. These were both compiled with Microsoft Visual Studio C++, so sorry if anyone has problems getting them to compile in their compilers.
YMIHere is offline                         Send a private message to YMIHere
Reply With Quote
Old 04-03-2005, 03:25 PM   #22
taikara
Abandonia Homie

 
Join Date: Jan 2005
Location: Shella, Kenya
Posts: 710
Default

Quote:
Originally posted by The Picard+Feb 23 2005, 12:38 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td>QUOTE (The Picard @ Feb 23 2005, 12:38 PM)</td></tr><tr><td id='QUOTE'><!--QuoteBegin-taikara@Feb 20 2005, 06:26 AM
My favorite program I did while learning was an artificial psychologist, using switches.

whee.

I asked it questions for hours.

Like:

Me: Am I crazy?
Dr: Yes, that does sound like an interesting theory.
I made a program I called "smalltalk" it was able to understand simple sentences and reply with sensicle answers. Great thing about it was that I did it all in MSX-BASIC. I was pretty proud of that program. Too bad I lost it.[/b][/quote]
Answers that made sense? :blink:

*bows to your skills*

I can barely do that just speaking, let alone write a program to do it!
taikara is offline                         Send a private message to taikara
Reply With Quote
Old 06-03-2005, 12:52 PM   #23
Ioncannon
Abandonia Homie

 
Join Date: Mar 2004
Location: Mississauga, Canada
Posts: 558
Send a message via MSN to Ioncannon
Default

I will try to write that program Kon Tiki. I can do it soopn if I had a compiler for mac. If I cannot find one, then it will take a while till I get my pc back...
Ioncannon is offline                         Send a private message to Ioncannon
Reply With Quote
Old 06-03-2005, 09:34 PM   #24
dragonLancer
Super Freak

 
Join Date: Feb 2005
Location: ,
Posts: 188
Send a message via MSN to dragonLancer
Default

wow your doing good (im still workin on it too) btw where are you on your C++ now?
__________________
----------------------------------------------------------

If anyone wants me I'll be in the Angry Dome!!!

----------------------------------------------------------
dragonLancer is offline                         Send a private message to dragonLancer
Reply With Quote
Old 08-03-2005, 04:07 AM   #25
Pangloth
Newbie

 
Join Date: Mar 2005
Location: ,
Posts: 10
Send a message via MSN to Pangloth
Default

Not trying to be the code nazi or anything but ANSI C++ mandates that main() is declared as returning an int and taking two arguments:

int main(int argc, char *argv[])

in which case you need to include a return statement.
Pangloth is offline                         Send a private message to Pangloth
Reply With Quote
Old 08-03-2005, 06:12 AM   #26
Kon-Tiki
[BANNED]

 
Join Date: Sep 2004
Location: Dentergem, Belgium
Posts: 1,811
Default

Does it even compile when not including a return in something else than a void-function? :blink: And what's the use of declaring it as an int if it doesn't return anything?
Kon-Tiki is offline                         Send a private message to Kon-Tiki
Reply With Quote
Old 08-03-2005, 03:37 PM   #27
Pangloth
Newbie

 
Join Date: Mar 2005
Location: ,
Posts: 10
Send a message via MSN to Pangloth
Default

Well, unfortunately the answer to many language semantic questions is "it depends on the compiler implementation" but in general a mature C++ compiler will yell at you for not returning a value when you said that the function should.

About main returning an int, this is only useful if the OS needs to examine the return value (either requested by a script or other reason), but my point was only that it's the standard and it's probably a good idea to do it this way. No reason not to.
Pangloth is offline                         Send a private message to Pangloth
Reply With Quote
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Program for download sh-tfish Old Suggestions 19 04-05-2009 09:19 AM
Dos Program pup Troubleshooting 4 30-06-2006 12:36 PM
An Old Dos Program JimmyJ Trash Can 12 21-06-2006 10:49 AM
Document Program Help nimicitor Tech Corner 3 20-10-2005 09:51 PM
Looking For A Good P2p Program MrBackAlleySka Tech Corner 17 07-09-2005 07:49 PM


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump
 


The current time is 02:44 PM (GMT)

 
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.