View unanswered posts | View active topics It is currently Sat Mar 23, 2019 7:40 pm



Reply to topic  [ 4 posts ] 
Um.... random numbers? 
Author Message
User avatar

Joined: Wed Mar 09, 2011 2:49 pm
Posts: 457
Gender: Male
Currently Playing: Ball Breaker with your sister. it's a real game...
Reply with quote
Code:
#include <iostream>
using namespace std;
int main ()

{
 int  choice;
   choice= 1,2,3,4,5;

   cout<< "COME PLAY A GUESSING GAME WITH ME. "<< "PICK ONE ON THE FIVE NUMBERS BELOW \n"<< "1    2     3     4    5 \n";
   cin>> choice  ;
   
   

   return  0;

}


So anyways I'm not taking a programing class this semester but I want to keep my mind sharp so I decided to make little games in the mean time. My game is a guessing game where you pick the lucky number. I heard of something called rand but I don't get could someone explain how I can make rand pick on of these 5 number randomly

_________________
As cold and empty as space. This is who I am.


Wed Mar 07, 2012 9:30 am
Profile
User avatar

Joined: Sat Aug 16, 2008 8:38 am
Posts: 6668
Location: Darkest Antartica
Country: Pakistan (pk)
Gender: Male
Skype: Thaiberium
Currently Playing: The Game
Reply with quote
I think the this is how you do it
Code:
int a = rand()%5;
int a++;

Not sure since I haven't programmed in a while. rand() generates a random number, run it through modulus of 5 to get a number between zero and four. All you need to do after that is add one to it.

_________________
Image


Wed Mar 07, 2012 1:07 pm
Profile
User avatar

Joined: Wed Mar 09, 2011 2:49 pm
Posts: 457
Gender: Male
Currently Playing: Ball Breaker with your sister. it's a real game...
Reply with quote
Nope that wasn't it. Is there a way to make rand randomly select just these 5 numbers. The numbers it's choose are way to off course.

_________________
As cold and empty as space. This is who I am.


Wed Mar 07, 2012 1:25 pm
Profile
User avatar

Joined: Sat Aug 16, 2008 8:38 am
Posts: 6668
Location: Darkest Antartica
Country: Pakistan (pk)
Gender: Male
Skype: Thaiberium
Currently Playing: The Game
Reply with quote
http://lmgtfy.com/?q=using+rand+in+c%2B%2B

I really think that was the easiest way to use rand() so if you have a better way, go ahead and use that.

_________________
Image


Fri Mar 09, 2012 2:19 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software for PTF.