Hi
is there a slick way of doing this
#include <iostream>
#include <string>
using namespace std;
int main() {
int a, b, c;
a = b = c = 5;
a==b?b==c?cout << "all the same\n"::;
}
thanks 11 1978
sonison.ja...@gmail.com wrote:
da*************@gmail.com wrote:
(a-b+c == c)
This is true if a == b, regardless of c.
I think it should be
(a-b+c == a)
This is true if b == c, regardless of a.
I don't see what's wrong with simply a == b && b == c.
Gary Wessle wrote:
Hi
is there a slick way of doing this
#include <iostream>
#include <string>
using namespace std;
int main() {
int a, b, c;
a = b = c = 5;
a==b?b==c?cout << "all the same\n"::;
}
thanks
This should work
if (!((a^b)|(b^c)))
{
cout << "all the same\n"
}
although I prefer
if (a == b && b == c)
{
cout << "all the same\n"
}
as this is probably more code efficient and definitely more clear
JB
"Harald van D3k" <tr*****@gmail.comwrites:
sonison.ja...@gmail.com wrote:
da*************@gmail.com wrote:
(a-b+c == c)
This is true if a == b, regardless of c.
I think it should be
(a-b+c == a)
This is true if b == c, regardless of a.
I don't see what's wrong with simply a == b && b == c.
there must be another problem with this
#include <iostream>
#include <string>
using namespace std;
int main() {
int a, b, c;
string ampm;
int wage = 50;
a = b = c = 5;
ampm = "am";
if(a==b && b==c)
ampm == "am"? return wage : return -wage;
}
g++ -c -o try.o try.cpp
try.cpp: In function 'int main()':
try.cpp:17: error: expected primary-expression before 'return'
try.cpp:17: error: expected `:' before 'return'
try.cpp:17: error: expected primary-expression before 'return'
try.cpp:17: error: expected `;' before 'return'
make: *** [try.o] Error 1
"Harald van D3k" <tr*****@gmail.comwrites:
sonison.ja...@gmail.com wrote:
da*************@gmail.com wrote:
(a-b+c == c)
This is true if a == b, regardless of c.
I think it should be
(a-b+c == a)
This is true if b == c, regardless of a.
I don't see what's wrong with simply a == b && b == c.
I am not sure whats wrong with this
#include <iostream>
#include <string>
using namespace std;
int main() {
int a, b, c;
string ampm;
int wage = 50;
a = b = c = 5;
ampm = "am";
if(a==b && b==c)
ampm == "am"? return wage : return -wage;
}
I get errors like
g++ -c -o try.o try.cpp
try.cpp: In function 'int main()':
try.cpp:16: error: expected primary-expression before 'return'
try.cpp:16: error: expected `:' before 'return'
try.cpp:16: error: expected primary-expression before 'return'
try.cpp:16: error: expected `;' before 'return'
make: *** [try.o] Error 1
Gary Wessle <ph****@yahoo.comwrites:
������!㍫*������� ������ਾ����⸮�� �⁷����������� ��������ਾ‾‾
���� ⤊�ਾ⁔���⁴���‽�� �����⸊�ਾ‾⁉⁴��� ������⡡ⵢ*‽��ਾ � �������*����� ��ਾ ���������❳⁷� �⁷�����‽��☦‽�� �������������⁴ �ਣ���������ਣ���� ����ਊ����������ਊ �*��*�*�*��* �����*�⁷�����* *‽‽‽‵�*���≡� * *���…*��⤊***� ‽�≡�����⁷������* ����������ਊ�* **�ⵯ⁴�⁴��ੴ���� ����❩�*��⤧�����ㄶ ��������������� ����❲���ੴ���� ������*����❲��� ੴ�����������⁰� �ⵥ��������‧���✊� ��ㄶ���������*�� �‧���✊���⨪*���� �ㄊ
not sure if it is only my system, but I am not able to read the above
posted section, it shows as lots of boxes in a grid with some boxes
have crosses and "?" and some other strange looking characters.
the bad post should have read,
int main(){
int a,b,c;
string ampl;
int wage = 50;
a = b = c = 5;
ampm = "am";
if(a==b && b==c)
ampm == "am"? return wage : return -wage;
this is not working, error will not be posted as I am typing this by
hand to avoid copy/paste which may have caused the bad previous post.
Gary Wessle wrote:
the bad post should have read,
int main(){
int a,b,c;
string ampl;
int wage = 50;
a = b = c = 5;
ampm = "am";
if(a==b && b==c)
ampm == "am"? return wage : return -wage;
bad syntax:
return ampm == "am" ? wage : -wage;
>
this is not working, error will not be posted as I am typing this by
hand to avoid copy/paste which may have caused the bad previous post.
Gary Wessle wrote:
this is not working, error will not be posted as I am typing this by
hand to avoid copy/paste which may have caused the bad previous post.
By the way, in this case you were lucky, the error was obvious. In
general, though, we're not psychic, and you would have not gotten any
answers until you posted both compilable code and the error message.
Gary Wessle wrote:
I am not sure whats wrong with this
#include <iostream>
#include <string>
using namespace std;
int main() {
int a, b, c;
string ampm;
int wage = 50;
a = b = c = 5;
ampm = "am";
if(a==b && b==c)
ampm == "am"? return wage : return -wage;
}
I get errors like
g++ -c -o try.o try.cpp
try.cpp: In function 'int main()':
try.cpp:16: error: expected primary-expression before 'return'
try.cpp:16: error: expected `:' before 'return'
try.cpp:16: error: expected primary-expression before 'return'
try.cpp:16: error: expected `;' before 'return'
make: *** [try.o] Error 1
This seems to be a separate question. In the future, please ask new
questions in new threads.
Your problem is that you're misusing the ternary operator (?:). You
could do:
return ampm == "am"? wage : -wage;
Cheers! --M This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: msnews.microsoft.com |
last post by:
Hello!
I'm Jim
by asp
How can show "abc" in textbox when click one botton?
|
by: Victor Irzak |
last post by:
Hello,
I have an ABC.
it supports:
ostream & operator <<
I also have a derived class that supports this operator.
How can I call operator << of the base class for derived object??? Is it...
|
by: Frank Natoli |
last post by:
Have two tables "abc" and "xyz", where "xyz" is a superset, column-wise, of
"abc".
Is there any simple way to inject all the rows of "abc" into "xyz"?
Tried "insert into xyz select * from abc"...
|
by: Rick N. Backer |
last post by:
I have an abstract base class that has char* members. Is an
assignment operator necessary for this abstract base class? Why or
why not?
Thanks in advance.
Ken Wilson
Amer. Dlx. Tele,...
|
by: Mike Smith |
last post by:
Sorry about the multiple post, but I just realized my prior post was in
a thread that dates back a couple of days, so people might not see it.
Which is considered better for writing interfaces in...
|
by: Jiong Feng |
last post by:
Hi,
I have a ASP.net application, which is in root folder.
I hope my http module to intercept requests like:
http://localhost/abc/def
http://localhost/abc/def/
http://localhost/abc/
where...
|
by: david |
last post by:
I have created a datagrid with ID dgEncounter in form design, and add a
HyperLink Column, Link, which is bounded to a field URLs that providing the
URL of the page to go for each record. That is...
|
by: Ron M. Newman |
last post by:
Hi,
Under what circumstances can I ever get an exception about not being able to
cast type "ABC" to type "ABC" if there's only one ABC class in the system
and it's loaded from a dynamic...
|
by: Umesh |
last post by:
I want to extract a string abc*xyz from a text file.
* indicates arbitrary no. of characters.
I'm only able to do it when the string has definite no. of characters
or the string length is...
|
by: winzone |
last post by:
Last time interview, I got this questions for test.
I would like to know which answer is correct.
Q: Assume you have a list "ABC" which contains structures of "XYZ". "ABC" has 10 "XYZ" objects...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: Shllpp 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |