I am making a program that emulates a slot machine. I have three functions, each of which represent one of the three reels. Each function vertically displays a three symbol sequence of the reel. How do I place each function side by side so that I get a 3 x 3 grid of the slot machine's values?
# include <ctime>
# include <cstdlib>
# include <iostream>
# include <iomanip>
usingnamespace std;
//Value between 1-20, random
// Each value represents a three symbol sequence on a reel
int LeftReel ()
{
return rand() % 21;
}
void LeftReelSymbol()
{
switch (LeftReel())
{
case 1:
cout << "Bell " << '\n' << '\n' << "Orange " << '\n' << '\n' << "Blueberry "<< '\n';
break;
case 2:
cout << "Orange " << '\n' << '\n' << "Blueberry " << '\n' << '\n' << "Bell "<< '\n';
break;
case 3:
cout << "Blueberry " << '\n' << '\n' << "Bell " << '\n' << '\n' << "Orange "<< '\n';
break;
case 4:
cout << "Bell " << '\n' << '\n' << "Orange " << '\n' << '\n' << "Lemon "<< '\n';
break;
case 5:
//Continues like this for all values between 1-20
}
}
int MiddleReel ()
{
return rand() % 21;
}
void MiddleReelSymbol()
{
//Same as LeftReelSymbol(), but different sequences
}
int RightReel ()
{
return rand() % 21;
}
void RightReelSymbol()
{
//Same as LeftReelSymbol(), but different sequences
}
int main()
{
srand(time(NULL));
cout << "Slot machine!" << '\n' << '\n';
//Here in the program, all of the functions display their outputs
//But instead of being lined up like a typical slot machine,
//It just ends up looking a list
LeftReelSymbol();
MiddleReelSymbol();
RightReelSymbol();
}
}
1) Put all the output into a string buffer and print the buffer all at the same time.
2) Use a console control program to allow you to define sub-windows in the console window and/or position the cursor in the window and write stuff there.
It looks like all you really need to do, though, is adjust your print width with something like: