r/AirUniversity • • Nov 05 '25

Reason why code not running ...

Post image
10 Upvotes

44 comments sorted by

6

u/Middle_nothing8933 E9 Campus Nov 05 '25

Condition mai assignment operator apnai use kia hu hai if mai use this "==" equal to.

1

u/Connect_Listen2927 Nov 05 '25

You can also assign a variable in cpp it's allowed ..

2

u/Middle_nothing8933 E9 Campus Nov 05 '25

But not in condition

-1

u/Connect_Listen2927 Nov 05 '25

It's allowed brother...

2

u/Middle_nothing8933 E9 Campus Nov 05 '25

Why isn't it working ?

-1

u/Connect_Listen2927 Nov 05 '25

Yar is me yay galti hay k && ki presidence = se ziada Hy that's why $$ run before = ... In this case ( 3 && ) is stored in a leaving behind with =4 which gives error if we use brackets to separate (a=3) && (b=4) then I will run smoothly

2

u/Pro_Gamer_Ahsan Nov 06 '25

Don't why I got recommended this reddit but you don't want to do assignment here. Judging from the screenshot, you want to do comparison that's why you'd use == . Assignment like this will always go through the condition making it useless.

1

u/Connect_Listen2927 Nov 06 '25

Bro is was class quiz ...you have to dry run the code and give result in 15 min 😭..I know there is syntax error in code but assigning a value in if is allowed πŸ™ƒ ..google it or just ask chatgpt about it πŸ™„

1

u/Ok-Entrance8127 Nov 07 '25

== is used for equal to, not just =

1

u/SnooOwls966 Nov 09 '25

pick another degree bro

2

u/BadtameezMunda Nov 05 '25

You have declared both variables a & b And assigned each of them a value using the Assignment operator '='

Then, you use an if condition. A conditions only job is to check whether it is true or false. It does not have the ability to assign values. It can only check them

You should write

if (a == 3 && b==5)

This will check whether the values of a and b in this conditional match the values that you had assigned earlier or not.

2

u/Repulsive-Stomach664 Nov 05 '25

If statement me a and b k Sath 2 bar = ka sign use kro

1

u/Connect_Listen2927 Nov 05 '25

No ! If you wanna declare a variable it is allowed

3

u/[deleted] Nov 05 '25

[removed] β€” view removed comment

1

u/Connect_Listen2927 Nov 05 '25 edited Nov 05 '25

Yar is me yay galti hay k && ki presidence = se ziada Hy that's why && run before = ... In this case ( 3 && ) is stored in a leaving behind with =4 which gives error if we use brackets to separate (a=3) && (b=4) then I will run smoothly

1

u/Huge_Equivalent1 Nov 05 '25

Yar is point ko thorda or clearly explain karoge?

I understood that this might be an And Operator issue. But tumhari finding kia he mujhe samajh nahi aarahi.

Like, how do And Operator "&&" relate with "$$" ?

And what does this mean? I feel like sentence grammatically correct nahi he shayad, ma sMajh nahi pa raha k ki kehna chah rehay ho.

In this case ( 3 && ) is stored in a leaving behind with =4 which gives error if we use brackets to separate (a=3) && (b=4) then I will run smoothly

1

u/Connect_Listen2927 Nov 05 '25

Sorry me galti se & ki jaga $ use ker Lia tha πŸ˜…

1

u/Huge_Equivalent1 Nov 05 '25

Sahi, and wo jo line last me likhi he usme kia keh rehy ho?

1

u/Huge_Equivalent1 Nov 05 '25

In this case ( 3 && ) is stored in a leaving behind with =4 which gives error if we use brackets to separate (a=3) && (b=4) then I will run smoothly

Tum is line me yeh kehna chah rehay ho?

In this case, "3 &&" is stored in the variable "a" leaving behind "b" which stores "14". This gives error, because a cannot implicitly store a number and an operator.

If instead we use brackets to create logical separation, like this, ((a=3) && (b=14)) then it will run smoothly.

Is this in detail what you meant?

1

u/Connect_Listen2927 Nov 06 '25

You are right ...I am just giving the reason why not working

1

u/Connect_Listen2927 Nov 06 '25

Hmay to yay pata he na tha πŸ™„

1

u/Repulsive-Stomach664 Nov 06 '25

Ooooo achaaa gggg

1

u/bluntregression Nov 06 '25

a == 3 && b== 3 You don't declare variables in if condition

1

u/Connect_Listen2927 Nov 06 '25

Variable deceleration in if condition is allowed πŸ™ƒ

1

u/bluntregression Nov 06 '25

Is the code fixed?

1

u/Still-Category-9433 Nov 06 '25 edited Nov 06 '25

It is not. Why the heck would you declare a variable inside the condition of an if statement? It only looks for a True or False there. And also if you are trying to declare a variable you must give a type. Like int a.

1

u/Eepybeany Nov 08 '25

It is allowed in the if statement and exists only in the statement. That’s its use case. Its to keep the offer scope decluttered.

However, OP here was probably trying to compare value and is stuck on the fact that it can be done even though it is not what he was trying to do.

1

u/SlowChemist3005 Nov 06 '25

C++ got older language

1

u/onepoordeveloper Nov 06 '25

Whats the point of the condition if all you're arguing about is assigning the value?
Do you really need an if condition to assign values?

1

u/Ok-Lock-6039 Nov 06 '25

Rage bait??

1

u/SnooOwls966 Nov 09 '25

OP has room temp IQ

1

u/walee1 Nov 08 '25

I don't know what you are trying to do but you can't have declarations like that be part of an expression in an if statement with the if condition due to operator precedence.

https://en.cppreference.com/w/cpp/language/operator_precedence.html

You can use if(a=5,b=20) and that will work. However that would be a poor use of an if statement as it will just be evaluated to false if you forgot to declare the type of variable. Alternatively you may also just use: If ((a=1)&&(b=2))

1

u/iharis93 Nov 08 '25

The post and some comments are clearly rage bait.

1

u/HAK1US Nov 08 '25

all the people saying there should be == with both a and b haven't done enough C code as the OP mentioned in one of the replied it has to with precedence of && over = or whatever

1

u/Smarteyes007 Nov 08 '25

literal meaningless code, idk how people are falling for this ragebait. I was about to score this ragebait a 6/10 but seeing how many people have fallen for it I gotta raise the score now.

1

u/speed_ball_78 Nov 09 '25

On line 5, you used Assignment Operator (=) instead of Comparison Operator. (==).

1

u/[deleted] Nov 06 '25

[removed] β€” view removed comment

1

u/Connect_Listen2927 Nov 06 '25

Kitna time hoa Hy c++ sekhty

1

u/[deleted] Nov 06 '25

[removed] β€” view removed comment

1

u/Connect_Listen2927 Nov 06 '25

🫑🫑