c++ - ?: operator on sprintf -


apparently python or of dynamically typed language not healthy programmer. anyways, i'm struggling c++ exercise , have quick question syntax. couldn't find source code applied (if possible).

can use statement includes ?: operator sprintf argument?. no-compling code idea:

return sprintf("the cosine of %2f %s %2f", angle, (angletype == "g" ? "degrees" : "radians"), result); 

angletype value entered user specifying if he's entering degrees or radians.

angle value angle.

result actual cosine value.

i wanted print message descriptive possible came this.

if possible?

thanks!

yes, can use ?: anywhere expression expected.

one of problems condition, angletype == "g". in c , c++, cannot compare strings that; need use strcmp or that. unless angletype std::string, in case should work.

the other problem seem expecting sprintf return string. instead, you responsible passing string, write output. since c++, it's better use std::string anyway!

if doesn't solve problem, post compiler error message!


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -