![]() |
#21 | ||
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Oct 2004
Location: ,
Posts: 7
|
![]() 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; } |
||
![]() ![]() |
|
![]() |
#22 | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jan 2005
Location: Shella, Kenya
Posts: 710
|
![]() 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! |
||
![]() ![]() |
|
![]() |
#23 | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() 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...
|
||
![]() ![]() |
|
![]() |
#24 | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() 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!!! ---------------------------------------------------------- |
||
![]() ![]() |
|
![]() |
#25 | ||
![]() ![]() ![]() ![]() |
![]() Not trying to be the code nazi or anything
int main(int argc, char *argv[]) in which case you need to include a return statement. |
||
![]() ![]() |
|
![]() |
#26 | ||
![]() ![]() ![]() Join Date: Sep 2004
Location: Dentergem, Belgium
Posts: 1,811
|
![]() 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?
|
||
![]() ![]() |
|
![]() |
#27 | ||
![]() ![]() ![]() ![]() |
![]() 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. |
||
![]() ![]() |
|
![]() |
![]() |
||||
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 |
|
|
||
  |