Hello, I am in need of assistance on how to correctly output a selection menu using the rand function and while loops. I aim to have the line of code randomly output different statements from the first two selections, and for the program to continuously loop the number 3 is typed into the console.
Here is a rough draft for my line of code.
#include<iostream>
#include<string>
using namespace std;
//Random Outputs?
while (number == 1){
cout<<"Good Luck is coming your way!\n"<<endl;
break;
}
while (number == 1){
cout<<"Bad Luck is coming your way!\n"<<endl;
break;
}
//Repeat Until Quit?
while (number == 1 || number == 2)
{
cout<<"**************"<<endl;
cout<<"Random Generator"<<endl;
cout<<"**************"<<endl;
cout<<"1. Fortune Cookie saying."<<endl;
cout<<"2. Ancient Proverb."<<endl;
cout<<"3. Quit"<<endl;
cin>>number;
if (number == 3); //Not Quitting Correctly?
//Not Repeating the Selection Outputs?
}
}
I am aware that the current line of code will not output what I want, and that the rand function and statements of the second selection have yet to be implemented.
#include <iostream>
#include <random>
// returns a random number from range [min,max)
int random_int( int min, int max)
{
// Initializes a pseudo-random engine with a random number
static std::default_random_engine e( std::random_device{}());
// Sets distribution parameters
std::uniform_int_distribution<> d(min, max-1);
// Returns a uniformly distributed value
return d(e);
}
int main()
{
for (int i = 0; i < 20; ++i)
{
std::cout << random_int(0,2); // range 0-1
std::cout << random_int(8,10); // range 8-9
}
}