can you tell me how i make a diffrent number from rand becuase it did work with me | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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

4th Oct 2022, 11:50 PM
khaled kh :)
khaled kh :) - avatar
7 Answers
+ 1
You should've put C++ in post tags; not your own name https://code.sololearn.com/W3uiji9X28C1/?ref=app
5th Oct 2022, 1:52 AM
Ipang
+ 1
Did you edit the code, it is not the same as when I first checked. This one you have now is incomplete
5th Oct 2022, 2:59 AM
Chris Coder
Chris Coder - avatar
+ 1
Your code is wrong Cus it cive me a same namer
5th Oct 2022, 4:08 PM
khaled kh :)
khaled kh :) - avatar
+ 1
What is the instruction?
5th Oct 2022, 4:58 PM
Chris Coder
Chris Coder - avatar
0
Thanks
5th Oct 2022, 3:29 PM
khaled kh :)
khaled kh :) - avatar
0
This code is diffrenet cus i change somethink and now it is completely but my issue is make a number with different item ?!
5th Oct 2022, 3:33 PM
khaled kh :)
khaled kh :) - avatar
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]; } }
6th Oct 2022, 11:54 AM
Bob_Li
Bob_Li - avatar