#Beginner Doubt.

118 messages · Page 1 of 1 (latest)

light yoke
#

I just wanted to write a code that could say when the three given inputs ( strings ) are same or not. But I am not able to do so. Any help is appreciated.

#

I was able to do this same for two names though

velvet raft
#

don't do using namespace std

Bad practice and it brings all of the symbols from std:: to global scope which can cause collisions

velvet raft
#

&& means and

#

|| means or

light yoke
#

Adding this to my notes

velvet raft
#

Hi

light yoke
velvet raft
light yoke
velvet raft
velvet raft
light yoke
#

I got to know if else users do not have good repo..

velvet raft
#

Perf is basiacltl the same

light yoke
velvet raft
light yoke
#

Interesting

#

This reminds me I named a variable abs, which was colliding with mathematic function abs

velvet raft
#

Yeaaa

light yoke
velvet raft
#

Or wait

#

#1471800141475217449

#

@light yoke

light yoke
#

Yes sir

light yoke
#

@velvet raft

#

Why did the program end when the input was 'j'

velvet raft
#

yellow

light yoke
velvet raft
#

and 0 > 0 is false so it exited

light yoke
velvet raft
light yoke
#

Like I want the loop to work even after someone entered j

light yoke
velvet raft
#

ive not worked with cin much 😭

light yoke
zealous wedge
brisk badger
velvet raft
#

what the sigma

brisk badger
#

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.)
}   ```
undone questBOT
#

@brisk badger has reached level 12. GG!

light yoke
#

Okk.... I think I did NOT understand it

tired marten
# light yoke

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

tired marten
azure shore
azure shore
#

input a valid number

#

or if uhh c++ supports

velvet raft
# light yoke

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 */ ...
azure shore
velvet raft
#

but that uses RTTI

#

it works most of the time

#

you should tyr it

azure shore
#

type() like gives you the type of thingy like if its a function a string or sum

velvet raft
#

yeaa thats what typeid does in C++

azure shore
#

then cnat u do

#

if typeid(variable) == string then repeat

#

like a what was that loop

velvet raft
#

what's the type of variable tho

azure shore
#

what was that LOO

#

WHAT WAS THE LOOP

velvet raft
#

it's gonna be int right

azure shore
#

I FORGOT

#

I FORGOT WAHT WAS THE LOOP

#

that was like

#

{

}while()

#

instead of while()
{

}

velvet raft
#
int x = -1;

while (x > 0) {
    bla bla
}
#

a

velvet raft
azure shore
#

for like repeating loops

#

foreadh loops or whatever

velvet raft
#

no clue what youre getting at

azure shore
#

THIS LOOP

velvet raft
#

oh

#

😭

azure shore
#

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

velvet raft
#

int x;

#

typeid(x) will always give int

#

because the variable's type is an int

azure shore
#

t

#

w

velvet raft
#

tmeplates are compile time brudda

azure shore
#

okay

#

so

#

idk

#

just

#

fix it

azure shore
#

will it give auto aswell

velvet raft
#

auto is also compile time

velvet raft
#

and then parse number

#

if not number then you handle

azure shore
#

smart

velvet raft
#

not my sol

azure shore
#

but i feel like there should be a simplified way to do ts