473,385 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

function that takes care of turn

i dont know of a better way to write this i am stuck. i want to tell the user whose turn it is : i get this error

error: expected `:' before ';' token

for this code below

Expand|Select|Wrap|Line Numbers
  1. int turn_it_is(int play1, int play2)
  2. {
  3.     cout << (((play1%2)==1)((play1:play2));
  4.     cout <<  " it's your turn ";
  5.     cin >> turn_it_is;
  6. }
Mar 30 '10 #1
4 1177
jkmyoung
2,057 Expert 2GB
I think you're missing the question mark, and the options shouldn't be encased together in parentheses.
Mar 30 '10 #2
whodgson
542 512MB
As jkmyoung says:
The ternary operator or conditional expression operator is:
condition ? expression1 : expression 2
e.g. min=(x<y?x:y) //min would be assigned the value of x if x<y else min=y
Mar 31 '10 #3
you can use this ternary operation on above line of cout, store the output on temperary variable, and write the the cout.
Mar 31 '10 #4
Dheeraj Joshi
1,123 Expert 1GB
What is
Expand|Select|Wrap|Line Numbers
  1. turn_it_is
  2.  
in the above code? And you need to fix the ternary operator.

Regards
Dheeraj Joshi
Mar 31 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: vijay | last post by:
Hello I wanted to understand a contradictory design of C++ class A {public: virtual void f(){ cout<<" base f"<<endl; } }; class B:public A {
6
by: gustav04 | last post by:
hi all i have a question: what is the difference between a c-function and an c++ class method (both do exactly the same thing). lets say, i have a function called print2std() and a class...
6
by: Stuart McGraw | last post by:
I am looking for a VBA "format" or "template" function, that is, a function that takes a format string and a varying number of arguments, and substitutes the argument values into the format string...
42
by: Martin Jørgensen | last post by:
Hi, I'm trying to move a matlab program into c language. For those who knows matlab, this is the line I want to program in c: hx(1:nx,1:ny) = 0; % nx=10, ny=10 It works on a 2-dimensional...
5
by: mailforpr | last post by:
typedef void(*int_arg)(int); typedef int_arg(*pf)(int*,int*,int_arg); I tried this: typedef void(*)(int)(*ultra)(int*,int*,void(*)(int)); and got a syntax error.
8
by: optimistx | last post by:
In excellent YAHOO user interface programs I see often extra parenthesis like this (foo=function(){ alert('I am foo'); })(); instead of bar=function(){
10
by: Raj | last post by:
I need a VB function to return array of collections like Private Type Employee empname as string address as string salary as integer deptno as integer End Type dim employees() as Employee
3
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I am a developer from C++ COM to C# COM. I feel confused about the entry point function for a C# COM object. In C++, we always initialize object through GetClassObject or...
4
by: istillshine | last post by:
I have a function foo, shown below. Is it a good idea to test each argument against my assumption? I think it is safer. However, I notice that people usually don't test the validity of...
26
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.