4806761279990q3zqy7 Jump to level 1 Write multiple if statements: If car Year is before 1967, print "Probably has few safety features." (without quotes). If after 1970, print "Probably has seat belts.. If after 1992, print "Probably has electronic stability control.. If after 2001, print 'Probably has airbags. End each phrase with period and newline. Ex: carYear = 1995 prints: Probably has seat belts. Probably has electronic stability control. 1 #include 2 3 int main(void) { 4 int carYear; 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 } 25 26 27 scanf("%d", &carYear); if (carYear 1967) { printf("Probably has few safety features. \n"); } if (carYear 1970) { printf("Probably has seat belts.\n"); } if (carYear 1992) { printf("Probably has electronic stability control.\n"); } if (carYear - 2001) { printf("Probably has airbags.\n"); } return 0; D-D-

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter2: Using Data
Section: Chapter Questions
Problem 14RQ
icon
Related questions
Question
100%

Need some help with this code, C Programming.

zy Section 3.7 - CIS 161: Introduction X C Write multiple if statements If carYear
A
с
□
zy zyBooks - Build Co... V Vimm's Lair: Preser...
75°F
Windy
✰ learn.zybooks.com/zybook/AVCCIS161 McCarySummer2023/chapter/3/section/7
Dashboard
=zyBooks My library > CIS 161: Introduction to C Programming home > 3.7: Detecting multiple features with branches
CHALLENGE 3.7.2: If-else statements.
ACTIVITY
480676.1279990.qx3zqy7
Jump to level 1
Write multiple if statements:
If carYear is before 1967, print "Probably has few safety features." (without quotes).
If after 1970, print "Probably has seat belts.".
If after 1992, print "Probably has electronic stability control.".
If after 2001, print "Probably has airbags.".
End each phrase with period and newline. Ex: carYear = 1995 prints:
Probably has seat belts.
Probably has electronic stability control.
6
7
8
9
1 #include <stdio.h>
2
3 int main(void) {
int carYear;
10
11
12
NENEKARANGON
13
14
15
16
17
18
Imported From Fire...
21
+
19 }
22
23
20 if (carYear 2001)
24 }
25
26
27 }
scanf("%d", &carYear);
if (carYear 1967)
{
printf("Probably has few safety features.\n");
if (carYear = 1970)
printf("Probably has seat belts.\n");
}
if (carYear = 1992)
{
printf("Probably has electronic stability control.\n");
printf("Probably has airbags.\n");
return 0;
Q Search
W
O
D-D
EzyBooks catalog
Help/FAQ
• VPN
Larry Williams
3:23 PM
6/1/2023
X
|||
Transcribed Image Text:zy Section 3.7 - CIS 161: Introduction X C Write multiple if statements If carYear A с □ zy zyBooks - Build Co... V Vimm's Lair: Preser... 75°F Windy ✰ learn.zybooks.com/zybook/AVCCIS161 McCarySummer2023/chapter/3/section/7 Dashboard =zyBooks My library > CIS 161: Introduction to C Programming home > 3.7: Detecting multiple features with branches CHALLENGE 3.7.2: If-else statements. ACTIVITY 480676.1279990.qx3zqy7 Jump to level 1 Write multiple if statements: If carYear is before 1967, print "Probably has few safety features." (without quotes). If after 1970, print "Probably has seat belts.". If after 1992, print "Probably has electronic stability control.". If after 2001, print "Probably has airbags.". End each phrase with period and newline. Ex: carYear = 1995 prints: Probably has seat belts. Probably has electronic stability control. 6 7 8 9 1 #include <stdio.h> 2 3 int main(void) { int carYear; 10 11 12 NENEKARANGON 13 14 15 16 17 18 Imported From Fire... 21 + 19 } 22 23 20 if (carYear 2001) 24 } 25 26 27 } scanf("%d", &carYear); if (carYear 1967) { printf("Probably has few safety features.\n"); if (carYear = 1970) printf("Probably has seat belts.\n"); } if (carYear = 1992) { printf("Probably has electronic stability control.\n"); printf("Probably has airbags.\n"); return 0; Q Search W O D-D EzyBooks catalog Help/FAQ • VPN Larry Williams 3:23 PM 6/1/2023 X |||
zy Section 3.7 - CIS 161: Introduction X C Write multiple if statements If carYear +
A
с
□
zy zyBooks - Build Co... V Vimm's Lair: Preser...
✰ learn.zybooks.com/zybook/AVCCIS161 McCarySummer2023/chapter/3/section/7
75°F
Windy
Dashboard
=zyBooks My library > CIS 161: Introduction to C Programming home > 3.7: Detecting multiple features with branches
24 }
25
26
27 }
Imported From Fire...
Check
return 0;
Try again
X One possible solution includes four if statements, one for each possible year.
Compilation error:
main.c:27:4: error: expected identifier or '('before 'return'
27 | return 0;
1
main.c:28:1: error: expected identifier or (before '' token
28 }
Note: Although the reported line number is in the uneditable part of the code, the error actually exists in your code. Tools often
don't recognize the problem until reaching a later line.
Nested if-else statements
A branch's statements can include any valid statements, including another if-else statement, which are known as nested if-else statements.
Nested if statements are commonly used to make decisions that are based on multiple features. Ex: To calculate a discount based on both
the number of items purchased and the total cost of those items, one if statement checks the number of items purchased and a nested if
statement can check the total cost.
Figure 3.7.2: Nested if-else.
if (numItems > 3) {
if (totalCost > 100) {
saleDiscount = 20;
}
else if (totalCost > 50) {
saleDiscount 10;
Q Search
// numItems > 3 and totalCost > 100
// numItems > 3 and total Cost > 50
Feedback?
O
EzyBooks catalog
Help/FAQ
• VPN
Larry Williams
3:24 PM
6/1/2023
X
|||
Transcribed Image Text:zy Section 3.7 - CIS 161: Introduction X C Write multiple if statements If carYear + A с □ zy zyBooks - Build Co... V Vimm's Lair: Preser... ✰ learn.zybooks.com/zybook/AVCCIS161 McCarySummer2023/chapter/3/section/7 75°F Windy Dashboard =zyBooks My library > CIS 161: Introduction to C Programming home > 3.7: Detecting multiple features with branches 24 } 25 26 27 } Imported From Fire... Check return 0; Try again X One possible solution includes four if statements, one for each possible year. Compilation error: main.c:27:4: error: expected identifier or '('before 'return' 27 | return 0; 1 main.c:28:1: error: expected identifier or (before '' token 28 } Note: Although the reported line number is in the uneditable part of the code, the error actually exists in your code. Tools often don't recognize the problem until reaching a later line. Nested if-else statements A branch's statements can include any valid statements, including another if-else statement, which are known as nested if-else statements. Nested if statements are commonly used to make decisions that are based on multiple features. Ex: To calculate a discount based on both the number of items purchased and the total cost of those items, one if statement checks the number of items purchased and a nested if statement can check the total cost. Figure 3.7.2: Nested if-else. if (numItems > 3) { if (totalCost > 100) { saleDiscount = 20; } else if (totalCost > 50) { saleDiscount 10; Q Search // numItems > 3 and totalCost > 100 // numItems > 3 and total Cost > 50 Feedback? O EzyBooks catalog Help/FAQ • VPN Larry Williams 3:24 PM 6/1/2023 X |||
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Concept of Parenthesis
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning