#what does this error mean?
143 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
@viral ivy
Your message appears to contain screenshots but no code. Please send code and error messages in text instead of screenshots if applicable!
#include <cstdlib>
#include <ctime>
#include <iostream>
int nfunc(int){
srand(time(0));
return rand() % 999999999;
}
bool primvar(int n) {
for (int i = 2; i <= n / 2; --i) {
if (n % i == 0) {
std::cout << "not prime";
return true;
}
}return false;
}
int main() {
int primerand;
for(bool c=true;!c;){
if (primvar(nfunc(int))){
primerand=(nfunc(int));
c=false;
}}
std::cout << primerand ;
return 0;
}```
You're putting types where the function parameter should be
And ofc, doing srand(0) every call makes it not random
Srand(0) should be called once per program
oh right,that should be in main
it's srand(time(0))
so what do i put in the function?
but if its a void function it wont return anything?
for(bool c=true;!c;) think about this loop for a second
You put parameter
The (int)
Not return
i mean when calling the function
I meant both
the sili
but the function doesnt need a parameter
well yes so it isnt void and returns int?
Bruh
int func(int)
The (int)
Not int but (int)
The thing in ()
i have misunderstood
lemme try something
ah wait,when calling the func with srand in main,will rand in the func still use srand? @tame turtle
When you call a function it executes code inside
Srand is a global function
Only one
its the same if it was for(bool c=false;c;) right?
And affects every rand()
i see
yep
Just make a normal variable and sane loop condition
This is unreadable
im gonna use this code to practise reverse engineering and check if that conditon affects the assembly as well
its unreadable on purpose
It doesnt affect assembly much
?
;asm -O2
int main(){
if(char var = 0){
var = 4;
}
}
main:
xor eax, eax
ret
this bot is very cool
shoudnt that be int var =4
why?doesnt that break the program
Var is already declared in if
The if wont ever execute
Only if you have else but then it'll still be as if the if doesnt exist
because its smart
Compilers do crazy optimizations
Anything goes as long as the program runs expectedly
;asm -O2
int main(){
int var =0;
if(var == 0){
var = 4;
}
}```
main:
xor eax, eax
ret
Where exactly
var is equal to 0
Eax is the function return value
If you want to know RE, learn asm
got it
so var wont equal to 4 there?
It doesn't because you don't use it
Try printing it out
To your terminal
It will still look different on asm
But just see
;asm -O2
#include <iostream>
int main(){
int var =0;
if(var == 0){
var = 4;
}
std::cout << var;
}```
main:
sub rsp, 8
mov esi, 4
mov edi, OFFSET FLAT:std::cout
call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
xor eax, eax
add rsp, 8
ret
Already optimizes it and just sets it to 4
Doesnt even set it
Just gives the 4 as param
cool,but in my program i do print it out
I mean ^^
alright holdon
You could do something like
X = 10 * 5 + 10/2 or whatever and you will still get this
Yup
Since nothing is done
So compiler just says meh, it does nothing so lets scrap it all
If you try printing it it will also not calculate them as the compiler can pre calculate it and write a value to give
The actual behavior stays the same either way
Your program behaves as if it did do whatever step you wrote in your code
On anything above O0 ofc
Gamer move
But yeah, as long as behavior remains the same, compiler can do whatever it wants
alright
int main() {
srand(time(0));
int primerand;
for (bool c = true; !c;) {
if (primvar(nfunc())) {
primerand = (nfunc());
c = false;
}
std::cout << c<<":bool is";
}
std::cout << primerand << ": prime is" << std::
return 0;
}
the bool is is probably unnecasarry
but it still prints 0,even after doing the same here
You mean this prints 0?
Yeah because your for loop never executes
Also not initializing variables
int primerand = 0;
Or primerand {} much preferred
why?
Try to think of what your for loop condition does
C = true
And loop will only execute while c is not true
!c means c is not true
It's the same thing as
If c != true
continue loop
got the bool to print,
is
if (primvar(randomNumber)) { /```
different than
``` if (primvar(nfunc())) {```?
Different in what way
do they do different things?not in the more redable way?
The primevar function might do something different, return different stuff but an if statement only does one thing
If(condition met)
Execute
wait,so is
primerand = (nfunc());
c = true;```
different from
```int randomNumber = nfunc();
if (primvar(randomNumber)) {
primerand = randomNumber; ```
ah it is
well i got it to technically work
its just that it keeps printing 3/other singler digit prime nums
and it takes like 2 whole seconds
