Nama: Erika Roselyn Husen NIM: 2702259235
Nama: Erika Roselyn Husen NIM: 2702259235
NIM : 2702259235
1. Pseudo code :
Declare Integer productCode, quantity, price, totalPrice, finalTotal, i
For i = 0 < tambah
Input productCode
If productCode < 0000000000 Then
Input quantity
If quantity < 0 Then
Input price
Set totalPrice = quantity * price
If tambah Then
Return 0;
Else
finalTotal = finalTotal + totalPrice[i]
End If
End If
End If
End
Flowchart :
4. a s/d e :
f s/d j :
5.
Nama : Erika Roselyn Husen
NIM : 2702259235
7. a.
b.
Nama : Erika Roselyn Husen
NIM : 2702259235
8. Nested selection occurs when the word IF appears more than once within IF statement.
9. Do while loop will execute the statement(s) at least once, then the condition is checked.
While loop checks the condition first and then executes the statement(s).
10.
11. a. Define a character array input of size 31 to allow for a maximum of 30 characters plus
the null terminator.
b. Use fgets to read the user’s input, and then we remove the newline character that fgets
might add to the end of the string.
c. Use the strlen function to calculate the length of the input string.
d. Check if the length of the input string is between 5 and 30 characters (inclusive). If it
is, we consider it valid; otherwise, it’s consideref invalid.
This code ensures that the input string length is within the specified range and provides
appropriate feedback to the user.
12.
13.
Nama : Erika Roselyn Husen
NIM : 2702259235
14.