Switch Statement Accomplishment

I Finally learned how to use switch statements and for some reason I felt the need to post a topic about it. Feel free to spam me about how this is a stupid topic, but I really felt the need to share xD
Well if you know switch then could you say what will be printed in the following program?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include	<stdio.h>    
int main( void )  
{
  	puts( "--- 1 ---" );
    	switch ( 0 )
  		if ( 1 ) case 0: puts( "0" );
  		else default: puts( "default" );

    	puts( "--- 2 ---" );
    	switch ( 0 )
  	while ( 0 )
  		if ( 1 ) case 0: puts( "0" );
  		else default: puts( "default" );

    	return ( 0 );  
}
Last edited on
Whats the "puts" thing? was this done is that visual C++ thing? 'cause I hear that has some different functions than most compilers like Code::Blocks.

It is a C code. puts is a standard functiion declared in <stdio.h>. You may use this code as C++ by including <cstdio> and using standard name space.
Last edited on
hm, so is it like the cout << function?
Yes you can use standard C++ stream functions as the operator << and you can use C-style output functions.

For example

1
2
3
4
5
6
#include <cstdio>

int main()
{
   std::puts( "Hello World!" );
}
Last edited on
ok so if that "puts" thing is pretty much exactly like cout << then that would print

--- 1 ---
0
--- 2 ---

would it not?
No, it is incorrect answer. The result will be

--- 1 ---
0
--- 2 ---
0
oh, oops


oh well ^.^ i was close
Last edited on
please take a look at this? http://www.cplusplus.com/forum/general/73095/
The enter character is still in the input buffer after you entered a value with the operator >>. So you shall clear the buffer before the next

cin.get(hold);
Topic archived. No new replies allowed.