943,929 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 21787
  • C RSS
Jun 30th, 2004
0

SLOT MACHINE PROGRAM... Help plsss!

Expand Post »
Hi to everyone here! I'm a newbie! I just wanna ask help from you especially from the administrator regarding my machine problem.....

I am asked by my proffesor to create a slot machine program.
This is how it goes...

The simulation starts by presenting the player with a menu of how much money to play for the round. The user has 3 options as shown in this sample run.

Welcome to the House of Fun!
Here, everyone is a winner!

You've spent $0 and won $0
How much are you going to play?
$ 10 for regular prize
$ 20 for increased prize value
$ 0 to quit
==> 65
Invalid! Enter again please...

How much are you going to play?
$ 10 for regular prize
$ 20 for increased prize value
$ 0 to quit
==> 10

Notice that the program checks whether the player entered correct values or not. If an incorrect value is entered, the program prompts the player to enter again.

If the player enters 10 or 20, the program will randomly generate 3 symbols. The symbols that can be generated are: APPLES, ARCHER, HEARTS, SMILES, or STARS!. However, the 5 symbols mentioned do not appear uniformly. The table that follows summarizes the statistics:

Symbol Chances of Appearing
STARS! appear 10 % of the time
SMILES appear 30 % of the time
HEARTS appear 30 % of the time
ARCHER appear 30 % of the time
APPLES appear 60 % of the time

The player wins money if the 3 generated symbols result to a lucky combination. If a lucky combination is generated, the prize in the 1st Credit is awarded. If the same lucky combination is obtained for the next round, then the 2nd Credit Prize is awarded.

Lucky Combinations

1st Combination
STARS!-STARS!-STARS!
1st Credit: $500
2nd Credit: $1000

2nd Combination
SMILES-SMILES-SMILES
1st Credit: $250
2nd Credit: $500

3rd Combination
HEARTS-HEARTS-HEARTS
1st Credit: $150
2nd Credit: $300

4th Combination
ARCHER-ARCHER-ARCHER
1st Credit: $100
2nd Credit: $200

5th Combination
any combination of a pair of any symbols except for APPLES
1st Credit: $20
2nd Credit: $40

6th Combination
a combination of SMILES, HEARTS and ARCHER
Credit: Especial Event if bet is $10
Credit: Especial Event 2 if bet is $20


The values above only hold if the user plays for $20. If the user played for only $10, a regular prize of $50 is given for the 1st to 4th combinations, and $10 for the 5th prize. Note that there are no 1st and 2nd credits for $10 games.

The 6th lucky combination gives the player access to a special event. This happens regardless of the user's game mode choice. There are two special events. If the user entered $10 the credit will be the special event 1 and if the user entered $20 the credit will be the special event 2( Actually my teacher said that I have the option to design whatever special the user will encounter.... since I know how to program ROCK-PAPER_SCISSORS Game and HANG-MAN GAME.... I chose them for my SPECIAL EVENT 1 & 2). If the user wins the special event 1, an award of $150 will be given to the player. If the user wins the especial event 2, an award of $300 will be given.

All unlucky combinations offer $0.

The program should continue to execute until the user chooses to quit (by entering 0).

SAMPLE RUN
Welcome to the House of Fun!
Here, everyone is a winner!

You've spent $0 and won $0
How much are you going to play?
$ 10 for regular prize
$ 20 for increased prize value
$ 0 to quit
==> 10

+--------+--------+--------+
| ARCHER | ARCHER | ARCHER |
+--------+--------+--------+
Congratulations! You get $50.


You've spent $10 and won $50
How much are you going to play?
$ 10 for regular prize
$ 20 for increased prize value
$ 0 to quit
==> 20

+--------+--------+--------+
| STARS! | APPLES | APPLES |
+--------+--------+--------+
Sorry, You get $0.

You've spent $30 and won $50
How much are you going to play?
$ 10 for regular prize
$ 20 for increased prize value
$ 0 to quit
==> 20

+--------+--------+--------+
| SMILES | HEARTS | SMILES |
+--------+--------+--------+
Congratulations! You get P20.

You've spent $50 and won $70
How much are you going to play?
$ 10 for regular prize
$ 20 for increased prize value
$ 0 to quit
==> 0

You spent a total of $50 and won $70
Thank You for Playing!

I already know the codes on the first part of the program. I have already tested ran and debugged the first part wherein the menu is displayed.
I mean this part....
Welcome to the House of Fun!
Here, everyone is a winner!

You've spent $0 and won $0
How much are you going to play?
$ 10 for regular prize
$ 20 for increased prize value
$ 0 to quit
==> 65
Invalid! Enter again please...

How much are you going to play?
$ 10 for regular prize
$ 20 for increased prize value
$ 0 to quit
==> 10

Now my problem is on the part of randomizing the symbols to be displayed....
I tried one of this codes....

  1. #include <stdio.h>
  2. #include <stdlib.h> /* where random and srand are defined */
  3. #include <time.h> /* where time functions are defined */
  4.  
  5. /*this function sets randomiztion seed value based on time*/
  6. void initRandom()
  7. { time_t random_seed;
  8.  
  9. random_seed=time(NULL);
  10. srand(random_seed);
  11. }
  12.  
  13. /*this function generates a pseudorandom number between 1 to 5*/
  14. int getRandomNum (int nLow, int nHigh)
  15. {
  16. int nRandomValue = nLow + rand() % (nHigh - nLow + 1);
  17. return nRandomValue;
  18. }
  19. main()
  20. {
  21. int nValue1, nValue2, nValue3;
  22. initRandom();
  23. nValue1 = getRandomNum(1,5);
  24. nValue2 = getRandomNum(1,5);
  25. nValue3 = getRandomNum(1,5);
  26.  
  27. switch (nValue1)
  28. {
  29. case 1:
  30. printf("STARS! ");
  31. break;
  32. case 2:
  33. printf("SMILES ");
  34. break;
  35. case 3:
  36. printf("HEARTS ");
  37. break;
  38. case 4:
  39. printf("ARCHERS ");
  40. break;
  41. case 5:
  42. printf("APPLES ");
  43. break;
  44. }
  45. switch (nValue2)
  46. {
  47. case 1:
  48. printf("STARS! ");
  49. break;
  50. case 2:
  51. printf("SMILES ");
  52. break;
  53. case 3:
  54. printf("HEARTS ");
  55. break;
  56. case 4:
  57. printf("ARCHERS ");
  58. break;
  59. case 5:
  60. printf("APPLES ");
  61. break;
  62. }
  63. switch (nValue3)
  64. {
  65. case 1:
  66. printf("STARS! ");
  67. break;
  68. case 2:
  69. printf("SMILES ");
  70. break;
  71. case 3:
  72. printf("HEARTS ");
  73. break;
  74. case 4:
  75. printf("ARCHERS ");
  76. break;
  77. case 5:
  78. printf("APPLES ");
  79. break;
  80. }
  81. }
Fortunately this code worked! But my problem is: "How am I going to edit the appearances of each symbol?" Like making the symbol "STARS!" appear 10% of the time and "APPLES" appear 60% of the time... is my function: "getRandomNum()" wrong? Am I going to change it?.... or what...
plss help me..... regarding this matter... I would really appreaciate if you could help me.... Thanks a lot!

P.S.
You could also send me the source code for my slot machine program.... If you think you know the shortest/ briefest way to code it..... then you could send it to me.... if you like :cheesy: .... I Would really really apreciate it! THANKS! :lol:
Last edited by adatapost; Feb 12th, 2010 at 7:09 am. Reason: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
datk0m is offline Offline
4 posts
since Jun 2004
Jun 30th, 2004
0

Re: SLOT MACHINE PROGRAM... Help plsss!

easy, give stars a larger numeric range. since apples are hard to get, make them 0 -9, then alot 10-69 for apples. and allow the other in the 30% remaining. any number randomly generated has a greater chance of falling in the larger block then the smaller one. therefor, you have just increased there chances of "getting" that number.

I don't do homework or write code for people, sorry. However; I am willing to aid in any problem you are trying to solve (as long as some genuine effort is put forth). I feal the best way for someone to learn is for them to complete the project on their own merit. (THINK FOR YOUSELF) If they dont wish to learn or do the work they should not have accepted the project or taken the course!
Reputation Points: 15
Solved Threads: 10
Unverified User
BinaryMayhem is offline Offline
173 posts
since Jun 2004
Jul 3rd, 2004
0

Re: SLOT MACHINE PROGRAM... Help plsss!

Well first off 60+30+30+30+10 does not equal 100 so its kind of hard to say that SMILES HEARTS AND ARCHERS happen 30% of the time.

Group them into the 30% and then pick one out of the 3.

This will help with the distibution with APPLES appearing most and STARS appearing least, but 1/3 (rounding) of the time you pick from 3 with equal probability of any of them.

So really a random number between 0 and 9, 0-5 = APPLE, 6-8 pick a SMILE HEART or ARCHER, 9=STAR. This really makes the statistic for SMILE HEART or APPLE 10% but there is no way to make it fit the distribution any other way.

Ask the prof if this is correct before continuing. If he/she says 'What do you think?' and it is a programming course, proceed. If it is a simulations course, ask more questions.

So one function that picks the symbols is the best approach.
Reputation Points: 13
Solved Threads: 5
Light Poster
Venjense is offline Offline
31 posts
since Oct 2003
Feb 6th, 2010
-4

Brief Fix

nIndex1 = getRandomNum(1,100);
nValue1 = nVect(nIndex1)
nIndex2 = getRandomNum(1,100);
nValue2 = nVect(nIndex2)
nIndex3 = getRandomNum(1,100);
nValue3 = nVect(nIndex3)
Populate nVect with candidate nValues in the appropriate proportions.
Example provides 1% granularity
William Geiger
--email snipped--
Last edited by WaltP; Feb 6th, 2010 at 8:27 pm. Reason: Don't post email addresses on forums.
Reputation Points: 6
Solved Threads: 1
Newbie Poster
whgeiger is offline Offline
4 posts
since Feb 2010
Feb 6th, 2010
0
Re: SLOT MACHINE PROGRAM... Help plsss!
Quick question , how are you making stars, archers, hearts appear on the screen ?
Reputation Points: 114
Solved Threads: 104
Master Poster
abhimanipal is offline Offline
736 posts
since Dec 2009
Feb 6th, 2010
1
Re: SLOT MACHINE PROGRAM... Help plsss!
Brief fix! For something posted 6 years ago? Not brief enough...
Moderator
Reputation Points: 3278
Solved Threads: 894
Posting Sage
WaltP is offline Offline
7,738 posts
since May 2006
Feb 7th, 2010
-1
Re: SLOT MACHINE PROGRAM... Help plsss!
Timing Issue
It should be obvious to all, that I overlooked the date of the original post. Brevity has nothing to do with this bogus issue.
Text Select
From nValue1, nValue2 & nValue3, calc pointers to the appropriate strings for printing.
Reputation Points: 6
Solved Threads: 1
Newbie Poster
whgeiger is offline Offline
4 posts
since Feb 2010
Feb 11th, 2010
2
Re: SLOT MACHINE PROGRAM... Help plsss!
Guys,

Thanks so much for your replies.
It's been six years since I made this newbie post. ) I'm a bit surprised that someone else is still replying to this. Makes me happy, though.

In those six years, I have learned a lot in programming, from creating simple tools, school machine projects, to doing complex and real-world applications, server side programing, web development, and a lot more.

I am currently working now in an international IT company. I'm very proud and thankful to you guys. You've been a part of my successful career. And also thanks to Daniweb forums!

This SLOT Machine Program is my first big step into the IT world. =D.
Last edited by datk0m; Feb 11th, 2010 at 11:47 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
datk0m is offline Offline
4 posts
since Jun 2004
Feb 11th, 2010
0
Re: SLOT MACHINE PROGRAM... Help plsss!
Click to Expand / Collapse  Quote originally posted by datk0m ...
Guys,

Thanks so much for your replies.
It's been six years since I made this newbie post. ) I'm a bit surprised that someone else is still replying to this. Makes me happy, though.
Doesn't make us happy.

Rhetorical question: With the help of abhimanipal and whgeiger, can you now finish your program? That should give you an idea why we're more annoyed.
Last edited by WaltP; Feb 11th, 2010 at 2:15 pm.
Moderator
Reputation Points: 3278
Solved Threads: 894
Posting Sage
WaltP is offline Offline
7,738 posts
since May 2006
Feb 12th, 2010
-1

Personna Non Grata

Click to Expand / Collapse  Quote originally posted by WaltP ...
Doesn't make us happy.

Rhetorical question: With the help of abhimanipal and whgeiger, can you now finish your program? That should give you an idea why we're more annoyed.
Some of us do not care if you are unhappy or annoyed by our posts, as we did not address them to you nor did we solicit your negative and unwelcome comments. If you do not like a particular post, particularly the ones not addressed to you, just move on to greener pastures where you feel predisposed to make a positive contribution.
Reputation Points: 6
Solved Threads: 1
Newbie Poster
whgeiger is offline Offline
4 posts
since Feb 2010

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: % letters
Next Thread in C Forum Timeline: Simple question: copy data pointed to by pointer, to an array





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC