Visual C++ :: Generating Lottery Numbers In Specified Range

Dec 4, 2012

Write a function named generateLotteryNumbers. The function is passed an int array of size 5. The function should generate 5 different lottery numbers in the range 1 to 50 inclusive and place the numbers in the array. The declaration is as follows:

void generateLotteryNumbers (int lotteryNumbers []);

Note that no data is passed in to the function. The array is used to return the function results. Thus the parameter is an OUT parameter. Do not display the result. Return the result.

Do not seed the random number generator inside the function. If you seed the random number generator inside the function and the function is called many times in the same second, your function will return the same results each time it is called.

I know how to generate the numbers in the specified range but I do not know how to test for duplicates. Here is the code I have so far:

Code:
//This program will test the "generateLotteryNumbers" function
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void generateLotteryNumbers (int lotteryNumbers[]);

[Code] ....

When I try to compile this, my compiler tells me that lines 41 and 46 require an array or pointer type.

View 8 Replies


ADVERTISEMENT

C# :: Generating Unique Random Numbers In The Range

Apr 28, 2014

We had to generate random, unique numbers in the range [1,15]. But running the program for several times showed a bug: It wouldn't always generate a new number for every repeated number. I can't figure out the problem, especially since it works half the time and I can't figure out what's making it work some times and not others.

bool flag1 = true, flag2 = true, flag3 = true;
int i, j = 1;
int[] A = new int[11];
Random rnd = new Random();
A[0] = rnd.Next(1, 15);
Console.WriteLine("1. = " + A[0]);

[Code] .....

View 14 Replies View Related

C/C++ :: Lottery Program That Generate 5 Different Numbers Between 1 And 20

Nov 4, 2014

I am a C++ beginner with no programming background. I need to write a lottery program that generate 5 non-duplicate numbers between 1 and 20. Here is my code and it just wont work.

#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <iomanip>
using namespace std;
int main() {
srand(time(NULL));
int lottery[5] = { 0, 0, 0, 0, 0 }, count = 0, rand_lottery;

[Code] ....

View 2 Replies View Related

C :: Generating Random Numbers

Oct 19, 2014

I have a program that generates random numbers. After the random number is generated, the program asks if you want to generate another random number. However, if you generate another random number, it is always the same as the first random number. How can I fix this?

View 5 Replies View Related

C++ :: Generating Big Random Numbers In C

Feb 16, 2013

I want to generate big random numbers in C(not C++ please).By "big" I mean integers much bigger than srand(time(NULL)) and rand() functions' limit(32767).

I tried writing: (note:I am not able to see "code" tag button in this editor,so I am not using it)

//****
int randomnumber;
srand( time(NULL) );
randomnumber = (( rand() % 33 ) * ( rand() % 33 ) * ( rand() % 33) * ( rand() * 33) * (rand() % 33 )) + 1
//****

But I have doubts about it's randomness quality.Also there is another problem,the program can't know the maximum random number it should use before user input,so maximum random number may need to use much smaller maximum random number according to user input.

Is there a better algorithm to create big random numbers in C?

View 2 Replies View Related

C++ :: Generating Big Random Numbers In C

Feb 15, 2013

I want to generate big random numbers in C(not C++).By "big" I mean integers much bigger than srand(time(NULL)) and rand() functions' limit(32767).

I tried writing: (note:I am not able to see "code" tag button in this editor,so I am not using it)

//****
int randomnumber;
srand( time(NULL) );
randomnumber = (( rand() % 33 ) * ( rand() % 33 ) * ( rand() % 33) * ( rand() * 33) * (rand() % 33 )) + 1
//****

But I have doubts about it's randomness quality.Also there is another problem,the program can't know the maximum random number it should use before user input,so maximum random number may need to use much smaller maximum random number according to user input.

Is there a better algorithm to create quality big random numbers in C?

View 14 Replies View Related

C++ :: Generating Random Numbers In Parallel

Nov 8, 2013

I generate a series of random numbers in parallel (using OpenMP), but depending on what number of threads I invoke, I get a different result. From that I conclude that I have made an error somewhere!

Here is the MWE, which generates a number between 0..1 and increments a variable if the generated variable is larger than 0.5:

Code:
#include <random>
typedef std::uniform_real_distribution<double> distr_uni;
#define max_threads 1
using namespace std;

[Code] ....

When I set max_threads=1 I get 50027, but when max_threads=60 (on a machine that supports it....) I get 50440.

The sensitive RNG and its engine I have declared within the parallelized area, so it's not really clear to me where the error can possibly be.

Looking for error that is apparently there?

View 8 Replies View Related

C :: Generating Random Numbers Without Repeating?

Sep 20, 2014

Inside my loop is this

srand(time(NULL))
a=rand()%10;

So it will generate numbers again and again as the loop goes on but it always repeat some numbers. My question is, how would you generate numbers without repeating? Somebody told me that i have to use auto increment, but i really have no idea about that.

View 8 Replies View Related

C++ :: Program That Keeps Generating Two Random Numbers Between 1 And 10

May 6, 2013

#include <ctime>
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {

[Code] ....

Write a program that keeps generating two random numbers between 1 and 10 and asks the user for the product of the two numbers, e.g.: "What is 4 x 6?". If the user answers correctly, the program responds with "Right!"; otherwise, it displays: Wrong! 4 x 6 = 24.

Generate as many pairs of numbers as specified and get the answers from the user for each. If at any time, both numbers are the same as last time, generate two new numbers before asking for the answer. Continue generating 2 new numbers until at least one is different from last time.

After presenting the number of pairs of numbers specified and getting the answers, display how many the user got right; e.g.: You got 4 of 5 right. Then, ask if he or she wants to play again, like so: "Do you want to play again? [y/n]". If the user answers with 'y' or 'Y', it again reads the number of questions to ask and generates that many pairs of numbers and reads the answers like before. If the answer is n or N, it quits generating numbers. If the answer is anything but y, Y, n or N, it tells the user to enter one of those letters until it is.

When the user decides to quit and has got less than 75% of all the questions right, the program displays the multiplication table (1x1 through 10x10) before terminating.

After displaying the table, randomly generate two numbers between 1 and 10, display their product and first number and ask the user to guess the second as more practice. For example, the program will generate 7 and 9 and will display 63 and 7 and the user must guess the second number (i.e.: 9). Do this 3 times. Do not repeat code. Use a loop to do this 3 times.

Use a nested for loop to display the table; a bunch of cout statements will not be acceptable. You must also use a loop for any part that calls for repetition such as generating 5 pairs of numbers.

The following is a sample interaction between the user and the program:

Enter the number of questions to ask: 5

1. What is 3 x 9? 27
Right!

2. What is 2 x 7? 14
Right!

3. What is 8 x 9? 63
Wrong! 8 x 9 = 72

4. What is 6 x 3? 21
Wrong! 6 x 3 = 18

5. What is 2 x 9? 18
Right!

You got 3 out of 5 right which is 60%.

Play agian? [y/n] n

View 10 Replies View Related

C++ :: Generating Sums Of Random Numbers

Sep 19, 2014

I'm trying to create a code that generates random numbers and spits out a sum average and lowest and highest number. I am stuck on the sum however and once I get that I think the average will fall into place. Here's what I have.

#include <iostream>
#include <iomanip>
#include <ctime>
#include <math.h>
using namespace std;

[Code] ....

I've noticed that it's almost always off by 1 or 3 for whatever reason

View 9 Replies View Related

C++ :: Generating All Possible Numbers In Base V Of P Digits

Apr 23, 2012

I'm sure this is pretty simple, but any way to do this. Essentially if I have an array with P collumns and V^P rows, how can I fill in all the combinations, that is, essentially, all possible numbers in base V of P digits.

For example, for P=3 and V=2

000
001
010
011
100
101
110
111

Keep in mind that this is an 2 dimensional array, not an array of ints.

For P=4 and V=3.

0000
0001
0002
0010
0011
0012
....

Having this array generated, the rest of work for what I'm trying to develop is trivial

This is a code I've written that should do the trick, but for some reason it gives this error on compiling:

"main.cpp:65: error: invalid types `double[3][9][double]' for array subscript"

Code:
for(i=0;i<P;i++) {
for(j=0;j<pow(V,i);j++) {
for(k=0;k<V;k++) {
for(l=0;l<pow(V,(P-i-1));l++) {
a[i][(j*V*pow(V,P-i-1) + l + k*pow(V,P-i-1))];
}
}
}
}

View 6 Replies View Related

C/C++ :: Checking Array And Generating Unique Numbers

Feb 11, 2014

Here is what I'm trying to accomplish (it is a rather simple program): A classroom of students are to grade a certain number of other exams. The exams should be distributed equally and RANDOMLY, every student should receive the same number of exams, and no student should receive their own exam to grade. The only problem I have is to generate unique random exams for each student. Right now, I have it set to where each exam is distributed the same number of times, every student gets the same number of exams to grade, and no one gets there own. However, I don't have any parameters that prevent one student from getting the same exam multiple time.

Here is an example output:

Student 1 will grade: 4 3 2 5 <- CORRECT OUTPUT (no exam appears more than once)
Student 2 will grade: 5 5 5 1 <- exam 5 appears three times
Student 3 will grade: 4 2 2 2 <- exam 2 appears three times
Student 4 will grade: 3 3 1 1 <- exams 3 and 1 each appear twice
Student 5 will grade: 1 3 4 4 <- exam 4 appears twice
(each exam appears four times and every student is assigned four exams. no one gets their own)

Here is my code (area of problem is close to the bottom):

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void create_class (int);
int main (void) {
srand(time(NULL));

[Code] ....

I tried keeping the exams for each student in the array exam and then checking each one every time I generate a number, but that didn't work.

View 8 Replies View Related

C++ :: Timer Function - Generating Seed For Random Numbers

Nov 14, 2014

for (int i=0; i<15; i++)
{
nx[i]=rand()%8+1;
printf("%d",nx[i]);
}

I want to the function of timer "srand(time(NULL))" to generate seed for random numbers. By running this for loop,I think I should expect random numbers ranging from 1 to 8.However, I get some wried numbers from the console window like 88,044,077,066,088,088,066,022,044,044,088,022,033,66814990522,-156026525933,1606416712. One more thing,I think I am going to have 15 outputs, but why I get 16 instead every time.

View 1 Replies View Related

Visual C++ :: Generating Dynamic Resource File?

Jan 3, 2014

We want to generate dynamic resource file for VC++ where the data will come from database (Oracle).

For an example, When a user log in the system, at that time if User is an English User, then some data in english language needs to be loaded in vc++ resource file. If the user is French then French data will be loaded into the resource file.

Right now all the data are hard-coded in the resource file but we want to load it dynamically from database, based on the login-user language.

How to do this dynamic implementation as I am not able to find any such concept in google.

View 8 Replies View Related

C++ :: Random Numbers Are Not In Specified Range

Nov 9, 2014

My program behaves weird... I wanted to generate 10 random numbers from 1 to 100 each of them bigger than previous, using the while loop and function that returns a random number in specified range.

When I run the program, I get numbers much bigger than 100, even negative number, and numbers are same every time I run the program.

Code:
#include <ctime>#include <cstdlib>
#include <iostream>
using namespace std;
int range(int low, int high);

[Code] .....

View 2 Replies View Related

C++ :: Prime Numbers In A Given Range

Feb 17, 2013

I have an assignment where I have to use two for loops. I need to ask the user for any two numbers and be able to list all the numbers in between and their factors and state whether or not the number is prime or not.

View 2 Replies View Related

C++ :: Finding A Range Between 2 Numbers?

Sep 23, 2013

Ok so I'm reading the Programming: Principles and Practice using C++ and Im stuck in Drill 4 part 5. It says:

Change the program so that it writes out the "numbers are almost equal" after writing out which is the larger and the smaller if the two numbers differ by less than 1.0/10000000

I'm using an If statement for it... I just need know what the formula is to check 2 numbers that were entered by person if they land within the range specified above. so then I can cout << "numbers are almost equal" << endl;

View 4 Replies View Related

C :: Calculate Prime Numbers In Range And Return Count Of Prime Numbers

Apr 28, 2013

I wrote a program which sends a starting and ending range to other processes and the processes calculate the prime numbers in that range and return the count of prime numbers to the head process, process 0. But this is not working properly at the moment. I realize I still have to split up the range based on how many processes I have...I still have not figured out how I want to set that up. I

Code:

#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
int isPrime(int num);
int main(int argc, char **argv){
}

[code]....

View 7 Replies View Related

C++ :: How To Make Array With A Range Of Numbers From 1 - 9 Only

Jan 29, 2013

I want to make an array with a range of number from 1-9 only. So if the user entered more than or less than the number indicated it will be error and ask the user to reinput the data. So far my code can be used to do so that if the user enter the number one by one... But if the user entered all the number in one shot the reentered value will be prompt to the back automatically for some reason...Let say 10,2,3,4 which was suppose to be 1,2,3,4 became 2,3,4,1 instead... here is the code:

#include<stdio.h>
void main() {
int num[4][4];
int row,col,x,y;
for(row=0;row<4;row++)

[Code] .....

View 3 Replies View Related

C++ :: Find All Prime Numbers In A Range

Oct 17, 2013

I am trying to create a program that lists all prime numbers within a range of two number. Why the below program isn't working?

#include <iostream>
using namespace std;
int main(){
int high_range;
int low_range;
int w;

[Code] .....

View 3 Replies View Related

C/C++ :: Finding Happy Numbers For A Given Range

Oct 5, 2014

I'm currently working on an assignment that finds all happy numbers for a given range. Such as 1- 10. My current code just isn't cutting it. I have to use a user defined function and return a bool value to main in order to output if the number is happy or if it sad. For some reason, I cannot get it to loop properly. the first number will be displayed correctly, but the second and third are just squares of the first number, instead of being squared by their single digits. I'm dividing by 10 to get the first number of the digit entered, then I'm using mod to get the remainder. One thing I did notice was that the num2 was putting a remainder of 30 for 130, and I'm not too sure what I need to do to change that, without affecting the whole program.

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdlib>
using namespace std;
Program calculates the bill for a user

[Code] ....

View 8 Replies View Related

C/C++ :: Get Double Random Numbers In Range From 0 To 1?

Apr 19, 2012

How to get double random numbers in the range from 0 to 1?

View 2 Replies View Related

C :: GSL And OpenMP - Getting Random Numbers That Are Out Of Expected Range

May 2, 2013

I am trying to parallelize some of my code with OpenMP. When I switch to using multiple threads I start getting random numbers that are out of the expected range.

Here is a small example:

Code:
#include <stdio.h>
#include </usr/local/include/gsl/gsl_rng.h>
#include </usr/local/include/gsl/gsl_randist.h>
int main() {
int mySeed=0;
const gsl_rng_type *T;
T = gsl_rng_ranlxs2;
gsl_rng *r_1 ;

[Code] .....

gsl_rng_uniform should only output number in the range [0,1) but with multiple threads it outputs larger number as well.

View 2 Replies View Related

C :: Loading Array With Random Numbers Within A Range

Oct 5, 2013

How would i go about loading an array with random numbers with in a range. For example, loading an array of 500 elements with random numbers in the range of 50-100.

View 9 Replies View Related

C :: Determine How Many Numbers In A Range Are Divisible By Third - Loop

Mar 1, 2013

I've pretty much finished the entire program, except for the actual calculation part.

"Given a range of values determine how many integers within that range, including the end points, are multiples of a third value entered by the user. The user should be permitted to enter as many of these third values as desired and your output will be the sum of total multiples found."

I've defined functions to take user input for the low range, high range and a do-while loop to take as many third inputs as the user wants (terminated by entering -1, as requested by the question)

To actually calculate if they're divisible, I found out that if A%B = 0, then they are divisible, so I thought I would create a loop where each value in the range between A and B is checked against the third value to see if they output a zero.

What I need to end up with is a program that tells the user how many integers are divisible by the numbers in the range, i.e: "Enter the low range value: 335 Enter the high range value: 475 Enter a value to check within the range: 17 Enter a value to check within the range: -1 There are 8 total values that are divisible by the numbers in the range." Going back to my original question, how would I create a loop or something to "check" how many values are equal to zero, and consequently increment a variable for each instance? (This is how I think it should be done)

Code:

#include <stdio.h>
//GLOBAL DECLARATIONS
int getlowR();
int gethighR(int);

[Code].....

View 4 Replies View Related

C++ :: Generate Random Numbers Within Specific Range?

Jun 5, 2014

So, there has got to be an easier way to generate random numbers within a specific range. Here is the code that I have been using, for a range of 1-6:

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

[Code]....

View 10 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved