lvalue required as left operand of assignment

heres the source code
cpp.sh/6rby6

the program is suppose to find a secret number that all four digits are different the digit in the thousands place is three times that of the number in the tens place the number should be odd and if you add up each digit in the 4 digit number it should equal 27
Last edited on
If you're checking equality, make sure you're using the == operator, not the assignment =. I think that's why you're getting that compiler error.
thanks for that dude your always helping me out i feel like but either way i did that and added cout << secret; but now the program just outputs 0
cpp.sh/67mdh

i know its something to do with my do while loop i just dont know where my logic is wrong
i think it may be because i have each num variable initialized at 0 so when it hits the first if statement num1 does = num2 so it just goes straight to output
Last edited on
i have uninitialized each num but then i get little caution things saying that they arent initialized and i still get a zero
You'd want to have numbers initialized to some value before trying to compare them.

A couple of things:

The numbers start at 0, but I don't see that they ever get changed. You mean to evaluate a different number each time through the loop I think.

The loop should stop once all four conditions are true? Each different number through the loop might evaluate true or false on different conditions. For each one then, if it meets the condition, the condition should be true, else, it should be false? Right now there's only an if condition, and with condition1 initialized to False, I don't see how it would ever get set to true.
all the question you had all yeses to them if that makes sense but do i need to increment num so it cycles through numbers till it hits the right one and what i mean by that is like ++num in the if statement?
You could increment num, but right now, each number in the final 4 digit number is a separate variable. The ones number could increment by one each time through the loop, but after it hits nine, there'd need to be logic to increment the tens number and start the ones back at 0. And so on for the hundreds and thousands numbers.

Another approach would be to have a single variable for number that increments each time through the loop, then have logic to isolate the individual numbers to check the four conditions.


Topic archived. No new replies allowed.