need assistance with matching colors

need assistance with a project im doing for class its matching colors basically my problem is how to go about using a delay bc u have to ask the user for how much of a delay they want but my problem is how to implemented from one void to another you will see what I mean when u see the source code and i also need some assistance displaying the whole if anyone can assist me out a little bit and explain what I have to do it would be highly appreciated thank you

#include <iostream>
#include <ctime>
#include "graph1.h"

using namespace std;

void getNoColors(int* no_colors);
void setColors(int* colors, int no_colors);
void getDelay(int* no_secs);
void game(int* colors, int no_colors, int delay);
void displayColors(int* colors, int no_colors, int delay);

int main()
{
//Variable Declaration/Initialization
const int MAX_COLORS = 5;
int no_colors = 0;
int no_secs=0;
int colors[MAX_COLORS];


//Display Graphics Window
displayGraphics();

//get the # of colors
getNoColors(&no_colors);

//set the colors
setColors(colors,no_colors);

//set the delay
getDelay(&no_secs);
}

void getNoColors(int* no_colors)
{
//tell user for number of colors
do{
cout << "Enter Number of Colors (2-5): ";
cin >> *no_colors;
}while(*no_colors>5 || *no_colors < 2);

}
void setColors(int* colors, int no_colors)
{
int i = 0;
int j = 0;
bool duplicate = false;

//Initialize Random Numbers
srand(time(0));

for(i=0; i<no_colors;i++)
{
do
{
//Generate Random Number
colors[i] = rand()%5;
duplicate = false;

//Check for Duplicates
for(j=0; j<i; j++)
{
if (colors[i] == colors[j])
{
duplicate = true;
break;
}
}
}while(duplicate);
}
}
void getDelay(int* no_secs)
{
cout<<"enter the Delay: ";
cin >> *no_secs;
}
void game(int* colors, int no_colors, int delay)
{

//Declaring varibles
int i;
int obj_no;
int m;
int x=0;
int y=0;


obj_no=drawRect(25,250,75,75);
setColor(obj_no, 255,0,0);

obj_no=drawRect(125,250,75,75);
setColor(obj_no,0,255,0);

obj_no=drawRect(225,250,75,75);
setColor(obj_no,0,0,255);

obj_no=drawRect(325,250,75,75);
setColor(obj_no,255,255,0);

obj_no=drawRect(425,250,75,75);
setColor(obj_no,255,0,255);


if (leftMouse(x,y))
{
for (int m=0; m< no_colors; m++)
{
if ((x>25)&&(x<100)&&(y>250)&&(y<325))
{
obj_no=colors[i];
}
}

}
}

}
void displayColors(int* colors, int no_colors, int delay)
{
}



Last edited on
This isn't tumblr. Please use punctuation and code tags: http://www.cplusplus.com/articles/jEywvCM9/

Is there a reason all the functions have to be void? Couldn't you just return the value, or pass it by reference?
Please use code tags by typing "code]", and please use punctuation.
Why do you have to return void? and if you can't, just use variables outside of the functions.
Example:
1
2
3
4
5
6
7
#include <iostream>
using namespace std;
string hello;

int main() {
    cout<<hello;
}
OK I'm sorry about that but because that is how the teacher gave it to us in order to learn to pass by pointers. I don't like the way he teaches he messes up on homework and doesn't explain the projects right that is why I was having a hard time working with the void functions.
Do you mean pass by reference?

What is it you're having trouble with exactly?
Topic archived. No new replies allowed.