Android Error

The series returns again! This time with color code formatting ! (Thanks to the Brilliant Team)

Alex is wondering how to build an android robot that can do Mathfights for him. He is currently stuck on one part of the phase, though:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
//Written in C
//Here is the bootloader....
printf("Booting up...");
int state = getAndroidState();   //gets current android state, this is a real function that returns an integer, whatever that means.
if (state == 0){     //means ok
    printf("Booted up correctly. My name is Alex number 2.");
}
else //this means that it has boot problems{
    printf("Uh oh...");
}

What was his error? Input the number from the chart below:

1 No errors.
2 No such function 'printf'
3 Comment placement incorrect
4 Forgotten Semicolon
5 Parse error: type 'int' cannot be explicitly casted as type 'char'
6 Parse error: type 'char' cannot be explicitly casted as type 'int'
7 Parse error: type 'int' cannot be implicitly casted as type 'char'
8 Parse error: type 'char' cannot be implicitly casted as type 'int'
9 I give up.

** Image credit: Flickr user D J


The answer is 3.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

8 solutions

Discussions for this problem are now closed

Shaikh Shiku
Apr 3, 2014

actually there is two types of errors here. first one is if i consider the compiler is only C compiler than it will not support the single line C++ type // comment. second is the opening brace of else block is commented out.

Well, let's say it is the loose variant of the compiler (I guess that one accepts C++ style comments)

Paul Paul - 6 years, 10 months ago
Bala Tweakbytes
Apr 5, 2014

Ehmm sorry to be a bum but C does not include the printf function by default. You need to import stdio.h to get it working. So there is one issue. Unless you assume you have a certain ANSI C compiler which does have the proper libraries. And also the comment was never an issue. Guess OP needs to modify the answer. I wasted two attempts, at last on 3rd decided to try the comment thing. Why are so many computer questions going wrong?

Ashish Chandra
Apr 4, 2014

Its always a good practice to use comments tags of this kind- /* */ rather than using // to avoid unnecessary commenting.

Kevin Mo
Mar 30, 2014

Look at the else{ statement. Notice the comments inside the else statement; it blocks out the {, making the else statement never starting. So the answer is, 3, Comment Placement incorrect.

Kind of in a rush right now, creating a new app for those super bored :P

No; without braces, the next statement is considered to be in the else block, so the else block will correctly run printf("Uh oh..."); . However, that makes the closing } a wild closing brace without no opening brace to match.

Ivan Koswara - 7 years, 2 months ago

Ugh! Sorry about that! So much trouble today!

Kevin Mo - 7 years, 2 months ago

Also the variable declaration is allowed only at program start in C where 'int state' is not allowed to declare and define.

dhruv Patel - 7 years, 2 months ago
Samad Malik
May 13, 2014

Opening brace for else statement is commented out

Yash Oswal
Apr 6, 2014

else { block is commented

Shubham Mathur
Apr 6, 2014

You comment placement is incorrect use /* */ instead of //

Daniel Lim
Mar 31, 2014

Use

/*this kind of comment*/

instead of

// this kind of comment

I prefer single line... but yes that will help solve the problem

Kevin Mo - 7 years, 2 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...