how is 8 10 not the correct answer?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

how is 8 10 not the correct answer?

 

You are working on problem set: PS4
}
ifElseMystery1 ♡
Language/Type:
C++ if/else
For each call to the following function, indicate what output is produced.
void mystery (int n) {
cout << n << " ";
if (n > 0) {
#
1
n = n - 5;
}
if (n < 0) {
n = n + 7;
} else {
n = n * 2;
}
cout << n << endl;
* You passed 0 of 4 tests. Try again.
question
mystery (8);
Pause) i
your answer
8 10
result
fail
Main Page → Exercises → PS4 → C++ → Solve an Exercise
mystery (8);
mystery (-3);
mystery (1);
mystery (0);
8 10
✔ Submit
Transcribed Image Text:You are working on problem set: PS4 } ifElseMystery1 ♡ Language/Type: C++ if/else For each call to the following function, indicate what output is produced. void mystery (int n) { cout << n << " "; if (n > 0) { # 1 n = n - 5; } if (n < 0) { n = n + 7; } else { n = n * 2; } cout << n << endl; * You passed 0 of 4 tests. Try again. question mystery (8); Pause) i your answer 8 10 result fail Main Page → Exercises → PS4 → C++ → Solve an Exercise mystery (8); mystery (-3); mystery (1); mystery (0); 8 10 ✔ Submit
Expert Solution
Step 1: Introduction

An if-else statement is a type of conditional statement commonly employed in programming to regulate the execution flow of a programme. The conditional statement permits the execution of a designated code block solely when a specified condition is satisfied, while an alternative code block is executed when the condition is not satisfied. This feature enables the execution of various programme branches, contingent upon distinct inputs or conditions. The if-else statement is conventionally implemented through the utilisation of the keywords "if," "else," and "else if" in order to delineate distinct conditions and the corresponding code to be executed. The utilisation of if-else statements in programming facilitates the creation of programmes that possess enhanced dynamism and versatility. This is achieved by enabling the execution of different actions in response to diverse inputs and situations.

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Bare Bones Programming Language
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education