c++ - variable might not have been initialized used -
i have made code make random fruit depending on probability
#include<iostream> #include"stdafx.h" #include <cstdlib> int main() { int blueberries; int grapefruit; int orange; int apple; int pineapple; int random = rand() % 100; if (random > orange & random < apple) { random = pineapple; } else if (random > pineapple & random < grapefruit) { random = apple; } else if (random > apple & random < blueberries) { random = grapefruit; } else if (random > 46) { random = blueberries; } else if (random < 10) { random = orange; } std::cout << random << ".\n"; system("pause"); return(0); }
but when want use it, pop "variable not initialized used" can explain me mean ?
you not initialising variables, means, content not defined. should set them initial value before using them, example int apple = 0;
. also, if want use logical and, should use operator &&, operator & bitwise and.
Comments
Post a Comment