New course! Every coder should learn Generative AI!
Try a free lesson0
can you tell me how i make a diffrent number from rand becuase it did work with me
#include <iostream> #include <cstdlib> using namespace std; int main() { srand(time(0)); int a[4]={}; for(int x=0;x<4;x++){ a[x]=rand() % 10; cout<<a[x]; } zero: if(a[0]==0){ a[0]=rand() %10; goto zero; } if(a[0]==a[1] ){ four: seven: one: a[0]=rand() %10; if(a[0]==0){ goto four; } } if(a[0]==a[2]){two: five: a[0]=rand() %10; if(a[0]==0){ goto five;} } if(a[0]==a[3]){six: a[0]=rand() %10; if(a[0]==0){ goto six; } if(a[1]==a[2]){ a[1]=rand() % 10
7 Answers
+ 1
You should've put C++ in post tags; not your own name
https://code.sololearn.com/W3uiji9X28C1/?ref=app
+ 1
Did you edit the code, it is not the same as when I first checked. This one you have now is incomplete
+ 1
Your code is wrong
Cus it cive me a same namer
+ 1
What is the instruction?
0
Thanks
0
This code is diffrenet cus i change somethink and now it is completely but my issue is make a number with different item ?!
0
Why are you even using goto?
It is unnecessary and only tangles up your code.
Jumping out of deeply nested loops should be one of the few occasions you might use goto. You don't even have to use it if you structure your code properly. This is just bad coding. Something you should avoid.
I get random result from this, without the goto spaghetti.
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
srand(time(0));
int a[4]={};
for(int x=0;x<4;x++){
a[x]=rand() % 9;
cout<<a[x];
}
}