C :: Generate Set Of Random Numbers On Board (2D Array) Like Candy Crush
Oct 15, 2013Assignment on making a program like candy crush but it is called as number crush.
View 3 RepliesAssignment on making a program like candy crush but it is called as number crush.
View 3 RepliesI am required to create a simple candy crush game.
I am this stage where I am required to print the 'box' for navigation purpose at the center of the board once the program initializes.
Here is the code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//FUNCTION: Draw the Board
[Code].....
I understand that the sequence could be to clear the screen and print the whole board with the indicated marker.
*Yes I am required to move the box in later part of the program but for now, I just need to get the box to show up at coordinate
Code: board[5][5]
I am stuck ...
I'm supposed to create a "game" that is similar to Candy Crush or Bejeweled. The assignment takes in a .txt file that contains a matrix of values from 1-5 and then assigns each value to a spot in a [10][10] array. Then an Escape Code function prints out colored pixels in place of the number values for each spot, creating a "game board" looking output. Finally, the program is supposed to look for any matches of 3 same-colored pixels and replace them with a white pixel and "XX". Then the program prints the corrected game board with the matches X'd out.
I have it mostly coded, but I've encountered a couple of issues.
1.) I am supposed to label the columns and rows 0-9, and while I have no problem coding the labels for the columns using printf( ), when I try to print the row labels I get a random string of numbers.
2.) I replaced the matches with white pixels by reassigning the value in the array to 7, for which the ANSI Escape Code is white. However, I'm unsure about how to print the "XX" in the same spot.
Here is the input(.txt) file and the output of the program so far:
And here is what I have coded at this point:
Code:
#include <stdio.h>
void printEscapeCode(int c);
int main(void)
{
/* Declare an image array to be gameboard */
int gameboard[10][10];
/* Declare variables and load in how many rows and columns */
int Nrows;
Nrows = 0;
[code]....
My program generates an array of random numbers. I want to then search a specific number within the array. If the number is in the array then a message apopears on the console saying that its there. I'm using the binary search algorithm to do this.
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <iomanip>
#include <cstring>
using namespace std;
int size;
int getSize() { return size; }
[Code] ......
I'm trying to generate random numbers so that I can assign people to teams. So far I have come up with this
Code:
int generateTeam(){
int i, teamNumber, c, n;
for (c = 0; c <= 5; c++) {
n = rand()%100 + 1;
}
[code]....
}//end generateTeam I'm not sure how to make it so that I can exclude the previous random number when generating the next one. As an example, I have 22 students and I get the number 19. Now I can't have 19 again because that guy already has it.
The program is to generate random numbers to a file and will have one integer parameter, Open a file and then using a loop write the required number of random numbers to the file. Scale the random numbers from 1 and 100 inclusive. Then closes the file .The last function will read the numbers in the file into your program. so far i have
Code: #include <iostream>
#include <string>
#include <iomanip>
#include <ctime>
#include <fstream>
#include <cstdlib>
[Code] .....
I am trying to generate 3 random numbers between 1 and 6 using a function called generate_rand. but everytime im having an error : no oprators "<<" matches these operands and the last error was :end of file found before the left brace
my program is the following :
# include<iostream>
#include<cstdlib>
using namespace std;
[Code]....
srand (time(NULL));
for(int i=0; i<N; i++) {
points[i].x=(rand()%(32767-(-32767)))+(-32767);
points[i].y=(rand()%(32767-(-32767)))+(-32767);
cout<<"x="<<points[i].x<<endl;
cout<<"y="<<points[i].y<<endl;
}
Im trying to generate random numbers between -32767 and +32767, where im going wrong, this code generates only negative numbers
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]....
I am trying to generate a random number between two numbers that the user gives me.
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void rand_int(const int &min, const int &max, int &val);
[Code] .....
I am just starting out programming and have an assignment due in the near future. the problem is I cant seem to figure it out. I started it already but got stuck cant seem to figure it out. Here is the assignment.
Create a program that will generate a list of 200 random numbers (ranging from 1-1000) and determine the medium, mode, and average of the list of numbers. Have the program display the original list ant then display the list in ascending and descending order on the screen.
I'm currently working on assignment which requires to generate a random permutation of the first N integers. For example, if N = 4, one possible answer is {3,1,2,4} without duplicates. {3,3,2,4} is not correct
to fill a[4], generate random numbers until you get one that is not already in a[0], a[1], ..., a[n-1]. for a[0] whatever random number you generate can be put in it. So here is my code. It seem to works but sometime it give duplicates.
#include <iostream>
#include <stdlib.h>
#include <time.h>
[Code].....
This is my coding so far and I am confused to what the constant for array size is
//initialize arrays
string states[ARRAY_SIZE]={"Alabama", "Alaska", "Arizona"};
string capital[ARRAY_SIZE]={"Montgomery", "Juneau", "Phoenix"};
while (play again) {
//generate random index number
int index = rand () % _______
what goes after the rand () % ?
The code below will generate combinations of numbers from 1 to 25 in an 15 numbers array. The only filter I've applied is that the sum of all the numbers in the vectors divided by 15 needs to be between 13 and 14.
I would like to count how many consecutive numbers there are in one combination, so that later i can apply another filter.. for example:
1 3 4 5 6 8 10 13 14 16 17 18 19 20 25
3 + 4 = 1
4 + 5 = 1
5 + 6 = 1
13 + 14 = 1
16 + 17 = 1
17 + 18 = 1
18 + 19 = 1
19 + 20 = 1
_____________
Count = 8, in this case..
I think it's not very difficult to do, but i just can't see how to do it.
#include <iostream>
#include <vector>
#include <numeric>
[Code]....
I'm programming tic tac toe but the board is not showing numbers, and it is simply stating the winner without any input: (the win conditions are not complete, but it shouldn't matter).
#include <iostream>
#include<string>
using namespace std;
//Write a two-player tic-tac-toe game; use enums when possible to represent the values of the board
char ticBoard[3][3];
char board[10];
void showBoard();
bool moveIsValid(int m);
int whoWon(); // 0 tied, 1 p1, 2 p.2
[Code] ....
i cannot print the values stored in the array ?
Code:
#include<stdio.h>
#include<math.h>
#include<time.h>
#include<stdlib.h>
double randf();
[Code] ....
So we're having an assignment for school where you code a Roulette game which simulates you playing and you can choose how many times you "play" to check how many times you'd win (if that makes any sense, im german :P)
Anyways, the problem is how do i store all the random generated numbers in an array while NOT doing this (it's just a snip):
Code:
void randomzahl(void){
int i;
int zahl5[5];
int zahl10[10];
int zahl100[100];
int zahl1000[1000];
int zahl10000[10000];
if(runden == 5)
[Code]...
i have a programming problem and i am unsure of what the final part is.the question is:
Write a program that fills an array with 10 random numbers between 1 and 20, displays the 10 numbers, and finds the sum of the 10 numbers. Call the getData, displayData, and getSum functions from the main function. Output the sum from the main program by calling the getSum function within a printf statement.
i am just really unsure of what this is--getData, displayData, and getSum functions from the main function. Output the sum from the main program by calling the getSum function within a printf statement.what i have got so far is;
Code:
#include <stdio.h>
#include <stdlib.h>
#define ARY_SIZE 10
int main() {
int randomNumbers[ARY_SIZE], sum = 0, i;
[Code]....
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 RelatedBelow is my code for a program that is suppose to generate and display six unique random numbers (between 1 and 54). The issue seems to be in my check for duplicates. I know what I am doing wrong but can't seem to find a way to fix it. I think it is getting stuck in an endless loop because the way I have written it looks like it checks the first value against itself which will of course look like a duplicate everytime.
Code:
#include<iostream>
#include<ctime>
using namespace std;
//function prototype
[Code]....
I'm trying to write a program that generates a random number between 50 and 200. I made a program that generates random numbers, but how to make those random numbers be in-between 50 and 200. Any example of a program that generates random numbers that are confined in-between certain values?
View 1 Replies View RelatedI just can't seem to get this right. What I want to happen is when the program runs a random word should pop up.
I have included my code. I'm not sure by putting tag around my code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
[Code].....
I am a very fresh c programme user, and need to fscanf data to arrays. Somehow it just doesn't gets recorded, wonder what is wrong with my code?
When I printf the array it always ends up with random numbers. Below is my programme which is just designed to read a doc and print it back out, as well as the text doc it is designed to read.
I am trying to sort an array of random numbers by passing it to a method Sort(), sort the array, and then pass the entire array back to the calling program. Each time I run this though, the array doesn't seem to sort. I'm not sure if the problem lies with my sorting algorithm or if it has something to do with calling the function.
Code:
static void HighAverage(int[] a) {
for (int i = 0; i < a.Length; i++) {
if ((i + 1) % 10 == 0 && i != 0)
[Code].....
so I'm creating a program that generates random sentences with structs..I'm trying to use structs and and create 4 different groupings article, noun, verb, and preposition. Then I'm trying to use "r = rand() % ;" to randomly pick one one word from each group to make a sentence. this is what i have
Code:
typedef enum article {
the = 1, a, one, some, any
} article;
typedef enum noun {
boy = 1, girl, dog, town, car
}
[code]....
I want to print different color names for "nb " times . I get the number " nb " from the user or from text file . if " nb = 3 " then I want to print any 3 different color names which means that I may print ( red , green , blue ) for example . and if " nb=5 " then I have to print any five different color names ( pink , blue , black , red ,white ) fore example .
Note : " nb " may be a large number ( 17 for example ). How can I do this ?