conditional statements and While Loop

conditional statements and While Loop

University

11 Qs

quiz-placeholder

Similar activities

Condition Programming Quiz

Condition Programming Quiz

1st Grade - University

9 Qs

PYTHON APTITUDE

PYTHON APTITUDE

University

12 Qs

Java Basics, operators and variables (CH/PT)

Java Basics, operators and variables (CH/PT)

University

16 Qs

CMDP2063 Unix and C Programming

CMDP2063 Unix and C Programming

University

15 Qs

Python Programming Competition

Python Programming Competition

University

12 Qs

CMDP2063 Unix and C Programming (Revision)

CMDP2063 Unix and C Programming (Revision)

University

15 Qs

Intro to JS: Functions, Scope & Objects

Intro to JS: Functions, Scope & Objects

11th Grade - University

8 Qs

Java_MCQ_3

Java_MCQ_3

University

15 Qs

conditional statements and While Loop

conditional statements and While Loop

Assessment

Quiz

Information Technology (IT)

University

Hard

Created by

Fatma Metwally

Used 5+ times

FREE Resource

11 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Media Image

What is the output of the following code if int x = 5?

  • Greater than 10

  • 10 or less

  • No output

  • Error

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Media Image

What is wrong with the following code?

  • Missing a semicolon

  • The if condition is missing parentheses

  • == should be =

  • Nothing, the code is correct

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

You want to assign a discount based on a customer’s age:

  • Age 0-12: "Child discount"

  • Age 13-18: "Teen discount"

  • Age 19-64: "Adult discount"

  • Age 65 and above: "Senior discount"

Which type of control structure is best suited for this scenario?

  • if

  • if-else if

  • switch

  • while

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Media Image

Given the following code, what would be the output if grade = 85;?

A

B

C

D

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Media Image

What is the output of the following code if int x = 5;?

  • Equal to 10

  • Not equal to 10

  • No output

  • Compilation error

Answer explanation

The condition mistakenly uses = for assignment instead of == for comparison, so x = 10 makes x equal to 10, which is non-zero (true), and the if block executes.

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Media Image

What will the following code print if int grade = 75;?

  • Excellent Done

  • Good Done

Good

  • Average Done

Answer explanation

grade is 75, so grade > 70 is true, which makes "Good" print. The final cout << " Done"; is outside the conditions, so "Done" is also printed.

7.

OPEN ENDED QUESTION

3 mins • 1 pt

Write a program that checks if a number is positive, negative, or zero. Display appropriate messages for each case.

Evaluate responses using AI:

OFF

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?