Mar 28, 2014 at 9:59am UTC
been a while since i've done C, but %c will be reading in one character and then you go on to test to see if that character is the string "red".
edit: if you compile this you should find this out :)
edit2: uses a std::string to hold your colour and read it in using this:
http://www.cplusplus.com/doc/tutorial/basic_io/
Last edited on Mar 28, 2014 at 10:01am UTC
Mar 28, 2014 at 10:10am UTC
if u want to use pure C u need to store the input in a c-string and compare it
using
strcmp()
from
<string.h>
1 2 3 4 5 6 7 8 9 10 11 12
char szColor[ 32 ];
scanf( "%s" , szColor );
if ( strcmp( szColor, "red" ) == 0 ) // strcmp() returns 0 if both string are equal
// ...
else if ( strcmp( szColor, "orange" ) == 0 )
// ...
else if ( strcmp( szColor, "green" ) == 0 )
// ...
else
// ...
you cannot use switch w/ case
Last edited on Mar 28, 2014 at 10:13am UTC
Mar 28, 2014 at 10:26am UTC
i'm actually using code blocks
Mar 28, 2014 at 10:37am UTC
i need help with my project please anybody..
Mar 28, 2014 at 10:45am UTC
i'm actually using code blocks
Are u using C or C++ ? if C++, stop using stdio and use IOstreams
Last edited on Mar 28, 2014 at 10:45am UTC