Another C++ Snip:
Post your C++ code snippets in here.
5 posts
Page 1 of 1
Here ya go:
Code: Select all
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <math.h>
using namespace std;
int rand_0toN1(int n);
void get_an_object();
int select_next_available(int n);
char *objects[4] = {"Cube", "Ball", "Spade", "Diamond"};
char *colors[13] = {"White", "Yellow", "Red", "Blue", "Green", "Crimson", "Cyan", "Orange", "Gold", "Aqua", "Purple", "Pink", "Black"};
int things_drawn[52];
int things_remaining = 52;
int main(){
int n, i;
srand(time(NULL));
while(1){
cout << "WARNING: DONT TYPE LETTERS TYPE NUMBERS" << endl;
cout << "Objects: Cube, Ball, Spade, Diamond" << endl;
cout << "Colors: White, Yellow, Red, Blue, Green, Crimson, Cyan, Orange, Gold, Aqua, " << endl;
cout << "Purple, Pink, Black" << endl;
cout << "Press 0 to exit: ";
cin >> n;
if (n == 0)
break;
for (i = 1; i <= n; i++)
get_an_object();
}
return 0;
}
void get_an_object(){
int c; // Random index (0 thru 12) into
// objects array.
int o; // Random index (0 thru 3) into
// colors array.
int n, thing;
n = rand_0toN1(things_remaining--);
thing = select_next_available(n);
c = thing % 13; // o = random 0 to 12
o = thing / 13; // c = random 0 to 3
cout << colors[c] << " " << objects[o] << endl;
cout << "----------------" << endl;
}
int select_next_available(int n){
int i = 0;
while (things_drawn[i])
i++;
while (n-- > 0){
i++;
while(things_drawn[i])
i++;
}
things_drawn[i] = true;
return i;
}
int rand_0toN1(int n){
return rand() % n;
}
You do not have the required permissions to view the files attached to this post.
What does this do?
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
You can test it out for youself.
But it only works in Devc++ tho.
Its like a game of picking.
Example: You type 1, it will randomly give you a Ball, Cube, Diamond, Spade with colors like Red Ball.
Just type 0 to exit it.
But it only works in Devc++ tho.
Its like a game of picking.
Example: You type 1, it will randomly give you a Ball, Cube, Diamond, Spade with colors like Red Ball.
Just type 0 to exit it.
Oh and dont worry, its perfectly harmless.
You can even ask the c++ programmers if this is safe or not.
You can even ask the c++ programmers if this is safe or not.
5 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023