The goal of this program is to have a random number generator that I can use in the main through a function. Then the values from the random number generator will trigger an action. This has if statements checking the values from the generator. The problem I am having is both strings, "Numbers 1 - 5" and "Numbers 6 - 10" appear instead of the if statements triggering only what is expected from them which would make only one of the strings appear.
#include <iostream>
#include <string>
#include <chrono>
void main()
{
void RanNum1to10();
int RanNum;
int x;
std::cin >> x;
if (x == 2)
{
std::cout << "X = 2" << std::endl << std::endl;
RanNum1to10();
if (RanNum = 1||2||3||4||5)
{
std::cout << "Number 1 - 5" << std::endl;
}
if (RanNum = 6||7||8||9||10)
{
std::cout << "Number 6 - 10" << std::endl;
}
}
system("pause");
}
void RanNum1to10()
{
(time(0));
int RanNum;
int x = 1+(rand() % 9 + 1);
switch(x)
{
case 1:
RanNum = 1;
case 2:
RanNum = 2;
case 3:
RanNum = 3;
case 4:
RanNum = 4;
case 5:
RanNum = 5;
case 6:
RanNum = 6;
case 7:
RanNum = 7;
case 8:
RanNum = 8;
case 9:
RanNum = 9;
default:
RanNum = 10;
}
}
Thank you.