+ 1
What does it mean by time limit exeded?
idk whats wring my code looks good but something iz off https://code.sololearn.com/ciJARBLbpP7V/?ref=app
6 odpowiedzi
+ 4
You are making two major mistakes:
1. You mistake the assignment operator ( = ) with the comparison operator ( == ). To check conditions, e.g. in if-statements or loops, always use the comparison operator! However, if you want to give a variable a value, like - probably - in line 20, use the first one.
2. You declared infinite loops in your code!
What is happening is that you assign 1 to x with every iteration since you use the assignment operator, but didnt specify any condition for the loop to stop, so it runs infinitly. Also, you didnt specify any changes to the variable, if you dont do that, x will always remain 0, so the condition x == 1 (what you probably meant) can never become false.
As a result of a too long compilation time, resulting from the infinite loop(s), the compilation is terminated with an exception "Time Limit Exceeded" thrown.
So, I'd suggest you to have a look at for-loops again, to make sure you understood their structure.
+ 1
For loop syntax
For(int x=1;x<=10; x++)
This means you want x to start at 1 and be incremented until it reaches 10, if you. Don’t need to increment anything then it is unnecessary
Random num syntax
A=rand() %100;
No brackets needed
If statement syntax
If(a==1) {cout.....}
If statements use comparison operators(==, <=, >=, !=) rather than assignment operators(=,+=,-=,/=,)
+ 1
thanks this helps alot i just got errors when i had =, but when i had==i got no errors so i thought i was right but i was still wrong, lol
+ 1
the whole point of this code was to implement classes, and objects but turns out i dont know loops. allways learning
0
I’d suggest that you familiarise yourself with control structures I.e. if-else, for, while, do while and finally switch &break first. Then move on to understanding arrays. Then understand the relationships between arrays and control structures. Start Learning about objects when you are comfortable with these concepts.
0
thanks