Test: AP Computer Science A

1.

What is wrong with the following code?                                

  1. int main()
  2. {
  3.    bool logic;
  4.    double sum=0;
  5.    for(j=0;j<3;j++)
  6.     {
  7.       sum=sum+j;
  8.     }
  9.  if (sum>10)
  10.   {
  11.     logic=1;
  12.    }
  13.  else
  14.   {
  15.     logic=0;
  16.    }
  17.   }
  18. }

Variable j is not defined.

There is an opening/closing bracket missing.

The code has no errors.

You cannot define the variable logic as a bool.

You must define the sum variable as an integer, not a double.

1/12 questions

0%
Learning Tools by Varsity Tutors