problems on using the if and else statement and updating the data.
-
im appreciate for both of you on helping me in the if and else part. However, when i try to checked AddOn1 and AddOn2, i got my price 2.50 instead of 3.70.
-
@Mr-Nobody645 said in problems on using the if and else statement and updating the data.:
im appreciate for both of you on helping me in the if and else part. However, when i try to checked AddOn1 and AddOn2, i got my price 2.50 instead of 3.70.
obviously, as
if (ui-> AddOn1 -> isChecked()){
price = 2.50;
}comes before everything else and its true so the rest of the checks is not executed
-
@Mr-Nobody645 said in problems on using the if and else statement and updating the data.:
However, when i try to checked AddOn1 and AddOn2, i got my price 2.50 instead of 3.70.
That's why I wrote earlier:
In which case you'll need to test that [
if (ui-> AddOn1-> isChecked() && ui-> AddOn2-> isChecked())
] before testingui-> AddOn1-> isChecked()
orui-> AddOn2-> isChecked()
individually. -
@sierdzio said in problems on using the if and else statement and updating the data.:
All modernt compilers also understand
and
as a synonym to&&
so you can do:I am speechless! Apart from the fact that I have never heard of this (old time C/C++ programmer, now returned to new C++). And apart from the fact that introducing
and
as a language keyword would potentially break one million old C/C++ programs which could have usedand
as a variable?You are obviously more expert than I, but do you want to recommend this to a newbie? I have never noticed
and
used in a C++ program, if OP is to produce standard code, and recognize others' code, would you not recommend sticking with&&
? -
@JonB apparently part of the standard since c++98
https://en.cppreference.com/w/cpp/keyword/and -
@J-Hilk , @sierdzio
Absolutely shocking! I see from https://en.cppreference.com/w/cpp/language/operator_alternative that there are actually 11 new reserved words for operators. Includingnot
, and even the stringcompl
, which I might have used as variables and would break upgrading to C++ '98.Thinking aloud, I believe all C operators were symbols and not words, part of the charm (for right or for wrong) of the language.
With all due respect to @sierdzio's comment, which I accept & respect, I have still never seen a piece of C++ code using any of these.... [And hence would caution a beginner against adopting these.]
[C++ looks like it's trying to be a Python-wannabe ;-) ]
-
@JonB said in problems on using the if and else statement and updating the data.:
I have still never seen a piece of C++ code using any of these
Me neither :-)
-
I have seen it but very, very rarely.
And hence would caution a beginner against adopting these
I'm split on this :D One one hand,
&&
is clearly, vastly, totally the established and well-known convention practically everywhere. So using it is definitely a good idea.But on the other hand,
and
is more readable and convenient. So it is also a good idea. -
@sierdzio said in problems on using the if and else statement and updating the data.:
But on the other hand, and is more readable and convenient.
In Pascal or Python, yes. When scanning C/C++ I expect to see all operators as symbols (and not some but not others) Next C++ will be offering
begin
/end
for{
/}
! [Some people used to do all this words-for-symbols via C#define
s.] I give up on the modern world, it's all going to pot... ;-) -
@JonB said in problems on using the if and else statement and updating the data.:
Next C++ will be offering begin/end for {/}!
you can use
{ ??< } ??> [ ??( ] ??) # ??= \ ??/ ^ ??' | ??! ~ ??-
but that was removed in c++17, :)
-
but that was removed in c++17, :)
Even better --- you start using new language constructs and then they remove them so that your code gets broken!
FWIW, I note from https://en.cppreference.com/w/cpp/language/operator_alternative
There are alternative spellings for several operators and other tokens that use non-ISO646 characters.
So the motivation never was "clarity", it's to do with people having funny keyboards....
-
@JonB said in problems on using the if and else statement and updating the data.:
funny keyboards
The hardware is innocent ;-P
-
whats next, espousing the virtues of trigraphs?