I am trying to use an array in an if statement to determine whether the value of x is rare or not.
If I do it this way everything is common.
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(){
int y[5] = {1,2,3,4,5};
srand(time(0));
for(int z = 0; z <= 50; z++){
int x = 1 + (rand()%6);
cout << z;
cout << " " <<x;
if(y[5] == x){
cout << ": Common" << endl;
}else{
cout << ": RARE" << endl;
}
}
But if I do it this way everything is rare.
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(){
int y[5] = {1,2,3,4,5};
srand(time(0));
for(int z = 0; z <= 50; z++){
int x = 1 + (rand()%6);
cout << z;
cout << " " <<x;
if(y[5] == ++x){
cout << ": Common" << endl;
}else{
cout << ": RARE" << endl;
}
}
I am really stumped on what to do can someone please help me?