100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.6 TrustPilot
logo-home
Exam (elaborations)

Condition statment in C language

Rating
-
Sold
-
Pages
8
Grade
A+
Uploaded on
22-03-2023
Written in
2022/2023

Condintions, If Elseif and Switch.

Content preview

SOLENT UNIVERSITY




Fig5-Task1-GradeA

In figure 6 the user input ‘a’ = 15 and ‘b’ = 9 and press 4 for subtraction as it is showing below.




Fig6-Task1-GradeA

In figure 7 is showing if the user enters any other number that is not an option the program will show the
message “Please enter 1 to 4 only.”




Fig7-Task1-GradeA

Assessment 2
Introduction of Conditional Statement

Conditional statement is using in programming to run a determinate condition. When the condition is true the
program will print the allocated end statement. For example if the 2nd of January is Monday the end statement
will say ‘It’s Bank Holiday, extra day off’ but if false the condition the program run a different code that say
‘Sorry, you need to go back to work’. In this case we can take in consideration two type of Conditional
Statement; If statement and Switch statement.
If statement, as we said before is using to check if a specific condition is true or false and execute when is
True but in a multiple conditional Switch statement is used more often as the performance are more efficient.
Switch statement is working in a different way, as it takes the given value and check inside the case if there is
a match. It is divided by case and for each of them there is a break; that will stop to check the condition when
it is true and print the allocated end statement. Both Conditional statements are used in this Assessment but
let’s give an example for each of them.

10

, SOLENT UNIVERSITY

Example of If statement:
Start

Condition

If true end statement

false

Else If true end statement

false

Else end statement

How we can see If statement simply working in this way, when the condition is true go straight to the end
statement of If, if it is false go to the next and print Else condition. Else is used when there are not condition
true, then the system will execute Else. For each of them there is a different statement that will be print. See
grade D to B for explanation how the program will print out when reach the condition.

Example of Switch statement:
Start

Condition

Case 1= true /break;
false

Case 2= true /break; End statement
false

default End Statement

How we can see for Switch Statement the condition will be checked if it is equal to the case if one of them is
true will print the end statement. Each case in switch has a break; to tell the program to stop to check other
condition. It’s recommended to use after the case a default for not have any issue in case that all of them are
false. Default is like Else in If statement, when all the case are false the program will execute the default
option. See grade A where switch statement has been used, it will give a visual understanding how the
program works in this conditional statement. (Gookin, 2004)
Grade D
This task requires to create a program that it will ask the user to select four options and after that it will
calculate the fees that the user will pay. The options are char, so for make sure that the program run properly
let’s give a space after the first quotation mark in scanf.
On the options the user can use ether uppercase or lowercase characters.
The program in option two to four it will multiplicate the cost for the allocated percentual fee. Also, to round
and take the two number after the point it has been used %.2 before the ‘f’ as float number.
%. and ‘X’ number after, it counts how many numbers needs to print after the dot. For example for show
25.64 is %.2f.




11

Document information

Uploaded on
March 22, 2023
Number of pages
8
Written in
2022/2023
Type
Exam (elaborations)
Contains
Unknown

Subjects

£5.99
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
micheleaccordino

Get to know the seller

Seller avatar
micheleaccordino Southampton Solent University
View profile
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
8
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Trending documents

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these revision notes.

Didn't get what you expected? Choose another document

No problem! You can straightaway pick a different document that better suits what you're after.

Pay as you like, start learning straight away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and smashed it. It really can be that simple.”

Alisha Student

Frequently asked questions