-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCase_Study3.c
66 lines (57 loc) · 1.77 KB
/
Case_Study3.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/////// Case Study 3 ///////
/////// Nested Control Statement ///////
/////// Pseudocode ///////
// 1 Initialize passes to zero
// 2 Initialize failures to zero
// 3 Initialize student to one
// 4
// 5 While student counter is less than or equal to ten
// 6 Input the next exam result
// 7
// 8 If the student passed
// 9 Add one to passes
// 10 else
// 11 Add one to failures
// 12
// 13 Add one to student counter
// 14
// 15 Print the number of passes
// 16 Print the number of failures
// 17 If more than eight students passed
// 18 Print “Bonus to instructor!”
#include <stdio.h>
// Function main begins program execution
int main(void)
{
// Initialize variables in definitions
int result; // One exam result
unsigned int passes = 0; // Number of passes
unsigned int failures = 0; // Number of failures
unsigned int student = 1; // Student counter
// Process 10 students using a counter-controlled loop
while (student <= 10)
{
// Prompt user for input and obtain value from the user
printf("%s", "Enter result (1=pass, 2=fail): ");
scanf("%d", &result);
// Check if the result is a pass (1)
if (result == 1)
{
passes = passes + 1; // Increment passes
}
else
{
failures = failures + 1; // Increment failures
}
student = student + 1; // Increment student counter
} // end while
// Termination phase; display the number of passes and failures
printf("Passed: %u\n", passes);
printf("Failed: %u\n", failures);
// If more than eight students passed, print "Bonus to instructor!"
if (passes > 8)
{
puts("Bonus to instructor!");
} // end if
return 0;
} // end function main