Example of how to get a random number in the range of six and return a value based upon it. Please Rate/Comment/Report Bugs
Rolling Die!
#include <iostream>
#include <cstdlib>
using namespace std;
void gamefunc();
int main(void)
{
gamefunc();
return 0;
}
void gamefunc()
{
int dice = (rand()%6)+1;
/*** Now we see what you rolled ***/
if(dice == 1)
{
cout << "*********\n";
cout << "* *\n";
cout << "* * *\n";
cout << "* *\n";
cout << "*********\n";
}
if(dice == 2)
{
cout << "*********\n";
cout << "* * *\n";
cout << "* *\n";
cout << "* * *\n";
cout << "*********\n";
}
if(dice == 3)
{
cout << "*********\n";
cout << "* * *\n";
cout << "* * *\n";
cout << "* * *\n";
cout << "*********\n";
}
if(dice == 4)
{
cout << "*********\n";
cout << "* * * *\n";
cout << "* *\n";
cout << "* * * *\n";
cout << "*********\n";
}
if(dice == 5)
{
cout << "*********\n";
cout << "* * * *\n";
cout << "* * *\n";
cout << "* * * *\n";
cout << "*********\n";
}
if(dice == 6)
{
cout << "*********\n";
cout << "* * * *\n";
cout << "* * * *\n";
cout << "* * * *\n";
cout << "*********\n";
}
}
wildgoose 420 Practically a Posting Shark
athlon32 56 Junior Poster in Training
jephthah 1,888 Posting Maven
necrolin 94 Posting Whiz in Training
MosaicFuneral 812 Nearly a Posting Virtuoso
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.