0
Output integers 0 and 1
Hi! This is probably something super simple, but i would like to write a simple arithmetic code that only outputs integer values 0 and 1 (not boolean).
4 Respostas
+ 2
Ohh, OK. The idea is simple, modulus (%) should do the job fine.
for (int i = 0; ; i++)
std::cout << i % 2;
E.g.
0%2 = 0
1%2 = 1
2%2 = 0
3%2 = 1
...
+ 4
Boolean values in C++ can actually be interpreted as 0 and 1, and will interact with other datatypes as such. They can be stored in integer variables and boolean variables. Putting that aside, are you looking to generate 1 or 0 randomly, or... ?
+ 2
No, I’m trying to make a for loop that uses an arithmetic that outputs 0,1,0,1,0,1,..... infinitely
+ 1
Thank you very much!!