Patrick
I've had this problem before
Patrick
without getting extremely complicated you will have to use a switch/case or if statements with each operator written out
Patrick
I find the cleanest way is to use a macro
Patrick
something like this: #DEFINE DoMath(OP) \ a OP b; use as: DoMath(<)
Ishikawa
if there no way to do it without if/else or switch/case?
Patrick
if there no way to do it without if/else or switch/case?
Unfortunately it will always be needed in some way because think: translating those ASCII characters < > <= >= into machine code will need some sort of translation no matter what you do.
Ishikawa
okay ty very much pal
Patrick
not a great illustration, but that's how I've done it in the past :)
Anonymous
double n1,n2; int cnt = 2; while(cnt == scanf("%lf%lf",&n1,&n2)){ // expression }
Yes but when i entered char or smth different ,there is still infinite loop again ,i am controlling this because i dont wanna infinite loop
Anonymous
can you clear your input format ?
double n1,n2; int cnt = 2; while(cnt == scanf("%lf%lf",&n1,&n2)){ if(cnt==2){ ... } else break: }
Anonymous
no it's not clear
If the user does not enter 2 double, I want it to exit the loop. If he does, I want it to continue. I cannot share the other lines. There are too many lines.
Shaurya
?
Anonymous
yes the end will happen if anything but double enters
Shaurya
yes the end will happen if anything but double enters
Form the unknown number of inputs you are considering 1. size of input will be only two or, 2. form the inputs , double will be only two ?
Anonymous
Size of input will be only two and ,form the inputs has to be double and will be only two
ברני
Is there a good site of quiz for practice c?... I'm always getting massive question and when I finish, new tesk of another thing.. and didn't get a chance to practice the first tesk...
Anonymous
Thanks i just want to handled char with double
Shaurya
thank you, the way of calculating is right, but I still dont understand why the code is not working
I reviewed your code 1. In count_perimeter() function check the condition of for loop and bracket 2. check the area calculation approach
Gulshan
Do anyone uses linux ? Who can help me, installing a c++ library
Anonymous
want some books about C++ STL?
Alex
why can`t you just access bit field member by its name?
Alex
you define order by writing fields one by one
Alex
this is called endian https://stackoverflow.com/questions/2100331/c-macro-definition-to-determine-big-endian-or-little-endian-machine
Alex
could you provide code and write two options? can`t understand
Alex
its about endian
Mr.
Mr.
Please someone help me
Roxifλsz 🇱🇹
/warn that is definitely not cpp
Mr.
Please I don't get you
Linking
Please I don't get you
This is html, not cpp.
Dima
lol
Dima
bruh
V01D
Dude that HTML is really, REALLY malformed
Ammar
If you think that is "Coding C++", then yes, you are crazy. Or just terminally stupid.
Dima
Ammar
You can use htonX/ntohX to uniform the byte order. For example: uint32_t x = htonl(0x01234567); x will always have the same value on any machine "if we see from its bytes and their order". htonl = host to network (long). But the value representation maybe different, depending on the machine endianess. That is the standard function, usually used to communicate over the network, because participant on the network maybe big endian machine or little endian machine, they uniform the byte order when it is transferred over the network (the data byte order always be big endian when the data is on the way). When the data arrives on target machine, they use ntohX to convert the byte order to corresponding machine endianess by using ntohX. uint32_t fix_x = ntohl(x); Where x is the data received from the network. ntohl = network to host (long) fix_x is now valid on the target machine, and its representation will be the same with the sender.
Ammar
Ammar
htonX and ntohX will be no operation on big endian machine.
Ammar
There's also the (at least theoretical) possibility that your program is running on some unusual hardware that uses a numeric representation that is neither big endian nor little endian. In that case, the htonl() and ntohl() functions for that environment would have been programmed to do the right thing (whatever that might be, as it needs to fullfil the standard network) to convert that machine's internal representation to the standard network representation (which is big endian) and back.
Ammar
https://man7.org/linux/man-pages/man3/byteorder.3.html
Ammar
Although it is related to network. It can be used for non networking activity too.
Anonymous
How to compare two double(a>b or a=b or a<b) number in C,i just did google but did not find any satisfied solution
Ammar
I didn't say that.
Ammar
Yes.
Ammar
The case was inside of a union. He gave those bitfields value from uint32_t foo, and he complained the values of two bitfields can be different (this was caused by endianess, because byte order will affect 8 groupped bits).
Ammar
Correct, %int8_t or char won't be affected by endianess.
Anonymous
At double and float they don't work
Ammar
Anonymous
line is y=x+6 point is double a,b; I want to compare this point is right or left side of this line ,i have a code at my pc but yeah if u try ;if double a==b ; u will see it is not working
Ammar
a == b for floating point numbers may be wrong. You should consider the epsilon tolerance in that case.
Anonymous
What about a>b and a<b
Ammar
I think this answer is something you are looking for https://stackoverflow.com/a/32334103/7275114
Anonymous
How to compare this
Anonymous
I think this answer is something you are looking for https://stackoverflow.com/a/32334103/7275114
Thanks but i saw that link before what i want is how to use this epsilon stuff with < smaller > bigger situations
Ammar
Thanks but i saw that link before what i want is how to use this epsilon stuff with < smaller > bigger situations
I think after you verify that your numbers are not equal by the given tolerance. The comparison operator < and > are valid to be used.
Ammar
// is a greater than b? bool is_greater(double a, double b) { if (is_equal(a, b)) { return false; } return a > b; }
Ammar
That looks valid to me.
Ammar
Maybe something wrong with your code.
Ammar
Sorry, I am not accepting private message for technical thing like that. Unless there is a private business between us. Just tell your problem in group. Thanks for your understanding.
Re
It is not giving the desired output can anyone plz help? M a beginner
Shaurya
It is not giving the desired output can anyone plz help? M a beginner
char will not compare to string You can take exam as char array then it will work
Re
char will not compare to string You can take exam as char array then it will work
I have tried by taking %c but even then its not working
Shaurya
I have tried by taking %c but even then its not working
visit the concept of char and char array how can we compare that
Anonymous
char exam[]
Anonymous
use strcmp instead of ==
Re
use strcmp instead of ==
Ohk let me try this
Anonymous
And u need to change “char emam;” to “char exam[10];”
Anonymous
The number must be great than ur string length + 1