Problems

I'm having problems with this code:
if ( choice== 1 )


printf( "--------------------------------------------------------------------------------\n");
printf( "You have now picked up the shiny gem, it's now in your bag.\nYou notice an entrance to a cave.");




if ( choice==2 )

printf( "--------------------------------------------------------------------------------\n");
printf( "You have just kicked the gem off the road.\n")


if ( choice==3 )

printf( "--------------------------------------------------------------------------------\n");
printf( "You have stomped the gem, it now appears to be broken.\n");

return 0;
}
What problems?

Build or runtime??

Andy
ORIGINAL code with CODE TAGS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
if ( choice== 1 )


printf( "--------------------------------------------------------------------------------\n");
printf( "You have now picked up the shiny gem, it's now in your bag.\nYou notice an entrance to a cave.");




if ( choice==2 )

printf( "--------------------------------------------------------------------------------\n");
printf( "You have just kicked the gem off the road.\n")


if ( choice==3 )

printf( "--------------------------------------------------------------------------------\n");
printf( "You have stomped the gem, it now appears to be broken.\n"); 

return 0;
}


POSSIBLY fixing code with CODE tags
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if ( choice== 1 ) {
printf( "--------------------------------------------------------------------------------\n");
printf( "You have now picked up the shiny gem, it's now in your bag.\nYou notice an entrance to a cave.");
}

if ( choice==2 ) {
printf( "--------------------------------------------------------------------------------\n");
printf( "You have just kicked the gem off the road.\n")
}

if ( choice==3 ) {
printf( "--------------------------------------------------------------------------------\n");
printf( "You have stomped the gem, it now appears to be broken.\n"); 
}

return 0;
}



And... Well "shorten" version of code (read: better writed... without tabs)... again with CODE tags
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
if ( choice== 1 ) {
printf( "--------------------------------------------------------------------------------\n");
printf( "You have now picked up the shiny gem, it's now in your bag.\nYou notice an entrance to a cave.");
} else if ( choice==2 ) {
printf( "--------------------------------------------------------------------------------\n");
printf( "You have just kicked the gem off the road.\n")
} else if ( choice==3 ) {
printf( "--------------------------------------------------------------------------------\n");
printf( "You have stomped the gem, it now appears to be broken.\n"); 
} else {
// Not a good choice
}

return 0;
}


hope this will help

And also....
Why you "print" same row of "--"'s instead printing them before if mess?
Last edited on
closed account (zb0S216C)
Just so you know, if statements without braces ({}) can only handle one statement.

Wazzak
Topic archived. No new replies allowed.