+ 2
C zero rand error
In my code I use const randomBit = rand() % 2; but then it get value 0 it show message: No output, when value is 1 it compleye code amd output. This value used only in if() condition. https://code.sololearn.com/c2370vnO4KPk/?ref=app
12 Réponses
+ 5
Vladimir, I have tested the code, setting the <randomBit> to zero, and 123, 25, 89 for <Var>, and I did get outputs, although the numbers in outputs doesn't seem to make any sense to me ...
What error message you get BTW? here I didn't get error message ...
Some input and expected outputs probably ...
+ 4
Hi Vladimir, I don't really understand how you expect the output to be with <randomBit> being zero, but maybe try these changes:
Line 8:
Add type after const (compiler warning, defaulted -> int)
const int randomBit = rand() % 2;
Line 26:
Simply increment <countf> by one
countf += 1;
A side note, why we have <count> and <countf>? can't we just use <count> for showing percentage? I'm a little confused here : )
+ 4
Vladimir, apologies, then my answer was incorrect : )
I'll stand by to see if others can come with better solution : )
(Edit)
It is possible that you get that "No output" message simply because of network traffic bottleneck on SoloLearn server, it comes quite often lately, your code has no problem.
+ 4
Vladimir, give me the numbers you used for testing, particularly the numbers that trigger errors, I'll see if there is something I can do ...
+ 3
Your code has no problem, even when the input is 0.
When it shows "No output",
actually it is Sololearn server problem.
Try click Run again
+ 2
I try many times. On zero value shows error, on one value it is work fine.
+ 2
It shows two types:
randomBit equal 0: output is how many percentage in one value, for example 1.125% = 1 Value.
randomBit equal 1: output is how many value in one percentage, for example 1.000% = 0.889 Value.
For this reason countf may take two parameters as int for int percentage increment and as float for int value increment, but in last case percentage increment is float value.
Simply I need random generator for two output variants, not for manual input.
+ 2
But it works fine then I simply type 0 or 1 in function call:
RecursvFcnTogetPrcntge(0);
Error also show when I try printf generated value, 1 show and 0 shpw error.
+ 2
Any number, I use 123 and 25 and 89, then generated value 1 it works, then zero show error.
+ 2
Input: 89
Error then generated value 0 on russian: Нет вывода. On english: No output. Then generated value 1 it works and show output:
1.000% = 0.89 Value
+ 2
If set randomBit directly to zero it works, if use rand() % 2 it shows error on value different from one, on one works fine.
const int randomBit = 0;
So it works. But if use rand it wont.
const int randomBit = rand() % 2;
+ 2
Thanks Gordie, it help and works now!!!