#Beginner Doubt.
118 messages · Page 1 of 1 (latest)
don't do using namespace std
Bad practice and it brings all of the symbols from std:: to global scope which can cause collisions
line 17:
if (s1 == s2 && s2 == s3)
&& means and
|| means or
Hi
I didn't get what you mean by second line but I'll stop doing it from now on
Omg
Clangster, I made a calculator using switch
Things like std::min and std::max become min and max which will collide with other things mamed the same thing
Whoa
I got to know if else users do not have good repo..
Perf is basiacltl the same
Like the mathematic function min(x, y)
Yea
Interesting
This reminds me I named a variable abs, which was colliding with mathematic function abs
Yeaaa
Where do I post my calculator
#1204181525336301609
Or wait
#1471800141475217449
@light yoke
Yes sir
yellow
Purple
if you don't give a valid numbr as input it sets to 0
and 0 > 0 is false so it exited
How do I avoid this
iiii don't know
Like I want the loop to work even after someone entered j
Oh well fair..
ive not worked with cin much 😭
Fair fair thank you
Have it receive a string instead of an integer. Then parse the string for a number and respond to non-numbers.
if you feed a char to an int with cin, im pretty sure it just assigns the raw binary to the int, so like im pretty sure a = 32
what the sigma
aparently cin has a .fail property?
std::cin >> value;
if (std::cin.fail()) {
// Handle error: clear flags and ignore buffer
std::cin.clear();
std::cin.ignore(256, '\n');
}```
interesting
int value;
if (std::cin >> value) {
// Input succeeded
} else {
// Input failed (wrong type, EOF, etc.)
} ```
@brisk badger has reached level 12. GG!
Okk.... I think I did NOT understand it
majority of the times for input you always wanna take it as a string and parse it into the data type you want unless it’s a bool and use an execption that’s how it’s done in a lot of industry
Yes, that helped me
Good
i mean u could use a if to check if the number was 0 and then tell them to input a valid number
what if they give 0
too bad too sad
input a valid number
or if uhh c++ supports
Undefined Behaviour; you have to initialize x before ever reading it
you have
int x; // uninitialized
while (x > 0) /* this is UB as you just read an uninitialized variable */ ...
does c++ support type() function
typeid()
but that uses RTTI
it works most of the time
you should tyr it
type() like gives you the type of thingy like if its a function a string or sum
yeaa thats what typeid does in C++
ohhhh
then cnat u do
if typeid(variable) == string then repeat
like a what was that loop
what's the type of variable tho
it's gonna be int right
I FORGOT
I FORGOT WAHT WAS THE LOOP
that was like
{
}while()
instead of while()
{
}
nah it was normal
no no it was like a while adter the brackets
for like repeating loops
foreadh loops or whatever
no clue what youre getting at
do {
// Code to execute
} while (condition); // Don't forget this semicolon!
THIS LOOP
do {
} while(typeid(s1) == "string" or "char")
basically
and since a int isnt a frickin string or number
you can
just put the rest of ur code afterw
w
but
no
int x;
typeid(x) will always give int
because the variable's type is an int
tmeplates are compile time brudda
what abt auto
will it give auto aswell
auto is also compile time
solution is to use std::string x; cin >> x
and then parse number
if not number then you handle
smart
not my sol
but i feel like there should be a simplified way to do ts