How to fix "1 value required as left operand of assignment"? [closed] - c

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I want to build a project, where a counter counts up, every time a measurement is under 800 and resets if a measurement is over 800. I tried lots of things, but many didn't work, and some were way to complicated. Please help me... This down there is my original code, which doesn't work.
const int sensor = A0;
int x;
void setup(){
x = 0;
}
void loop(){
int Val = analogRead(sensor);
if(Val =< 800){
x + 1;
}
else{
x = 0;
}
delay(250);
}

Inside your if condition, you are not setting the value of variable. You are just giving an expression.
if(Val =< 800){
x + 1;
}
The correct code would be assigning the new value to the variable again, and also your relational operator is wrong.. it should be <=
if(Val <= 800){
x = x + 1;
}

Related

sum += (i*8); beginner can some one explain the problem I’m getting confused [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 months ago.
Improve this question
sum += (i\*8);
Can some one explain the problem? I, as a beginner, I am getting confused.
#include<stdio.h>
int main(){
int sum = 0;
for (int i == 1; i < 11; i ++)
{
sum += (i*8);
} I
printf("The value of sum is %d", sum);
return 0;
}
can someone explain
Instead of write i == 1, write i = 1. That assigns 1 to the variable i.
i == 1 : comparison
i = 1 : assignment

When I execute the following code, there is no output, what could be the cause? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
Here is my C code. I am not getting any output. Please help. I also tried adding the initialization of inside the main function, then also I am not getting any output.
#include <stdio.h>
int x = 10;
int main()
{
if (x = 20)
{
x = -1;
}
else
{
printf("x not eqaul to 20\n");
}
if (x > 0)
{
printf("x not greather than 0\n");
}
else
{
/* notjing */
}
return 0;
}
So in the first if-statement you wrote if(x=20). This is not a conditunal argument, this is a mathematical operand.
So x will be set to 20; afterworths it will be set to -1. And no printf() will be called.
If think you wanted to use if(x==20).

I can't understand what's going wrong in this program [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
#include<math.h>
#include<stdio.h>
int main(void)
{
int i = 0;
int f = 10000;
int div1 = (powl(10,i));
int temp1 = f/div1;
for(i = 2; temp1 > 1; i++)
{
printf("%i\n",temp1);
}
}
As far as I know, the value of div1 should be 100,1000,10000... With corresponding increments in I. Then temp1 should be 100,10, then loop stops (?). But I get an endless loop of 10000 10000 10000 10000......
Can someone explain what am I doing wrong?
The for loop checks for temp1, but temp1 is not modified in the loop's body. Try putting the desired modification inside the loop's body or as the last expression in the for loop; the variable i is perhaps not necessary at all.
Your for statement should have like this. You missed to call those to statement inside your for loop
for(i = 2; temp1 > 1; i++)
{
div1 = (powl(10,i));
temp1 = f/div1;
printf("%i\n",temp1);
}

Why is this an endless loop? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
First of all sorry for this, I really think it is a silly question but I've been stuck on this for a while. So maybe you can help me. The problem is I don't truly understand what's wrong in the code. So let's look up.
void enter()
{
int init= 1, end= 2;
float jump= 0.2;
create(init, end, jump);
}
void create(int Init, int End, float Jump)
{
float i;
int total = 0;
for(i = Init; i < End; i + Jump)
total += 1;
}
It does not exit the loop and I don't understand why.
The problem is here:
i + Jump
That does not change i, it simply evaluates. Change it to this:
i += Jump
and it should work fine.
The loop is infinit because variable i is not being changed within the loop. Change this statement
for(i = Init; i < End; i + Jump)
to
for(i = Init; i < End; i += Jump)
Also maybe there is a sense to define the function as having return type int is not there? For example
int create(int Init, int End, float Jump)
{
//...
return total;
}
i + Jump this does not modify i and hence i < End is always evaluated as TRUE, as per the initial condition (Init being less than End).
You need to change to i += End to keep incrementing the value of i.

Too many arguments to function 'rand'? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have only used the function twice and it displays the aforementioned error. Can someone explain as to why the compiler does that?
void printrandom()
{
int x = (rand(5)+1);
int y = (rand(5)+1);
printf("%d and %d - a total of %d", x, y, (x+y));
}
It is actually rand(void), which is why you are getting that error.
Try int x = (rand() % 5) + 1;
EDIT as Daniel points out, using % will actually affect the probability. See his link for how to address this issue.
Declaration for rand() function is
int rand(void);
This means that it takes no arguments. Remove 5 from rand. If you want to generate random numbers from 1 to 5, the you can do this as
int x = rand()%5 + 1;

Resources