The McLeodGaming forums were permanently closed on April 30th, 2020. You are currently viewing a read-only archive.
View unanswered posts | View active topics It is currently Fri May 15, 2020 5:51 am



 [ 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...
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
User avatar

Joined: Sat Aug 16, 2008 8:38 am
Posts: 6670
Location: Darkest Antartica
Country: Pakistan (pk)
Gender: Male
Skype: Thaiberium
Currently Playing: The Game
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
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...
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
User avatar

Joined: Sat Aug 16, 2008 8:38 am
Posts: 6670
Location: Darkest Antartica
Country: Pakistan (pk)
Gender: Male
Skype: Thaiberium
Currently Playing: The Game
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
Display posts from previous:  Sort by  
 [ 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

cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software for PTF.