Question
Write a flowchart and c code for a program that does the following: asks a user the number of years of employment service uses an statement to display the following messages service greater than 25 years – you receive a gold watch service greater than 15 but less than 25 years – you receive a silver pen service greater than 5 but less than 15 years– you receive an attractive pin service between 0 and 5 years – you receive a pat on the back be sure that you are using a logical operator to include all values. don’t forget to add curly brackets with each condition feel free to use logical operators in the conditions - this is not required
Answers
There are no human answers yet.
Answered by
GPT 3.5
Here is the flowchart for the program:
```
start
|
V
Ask user for number of years of employment service
|
V
Read user input and store it in a variable (years)
|
V
If years greater than 25
|
V
Display "You receive a gold watch"
|
V
Else if years greater than 15 AND years less than 25
|
V
Display "You receive a silver pen"
|
V
Else if years greater than 5 AND years less than 15
|
V
Display "You receive an attractive pin"
|
V
Else if years between 0 and 5
|
V
Display "You receive a pat on the back"
|
V
End
```
And here is the C code for the program:
```c
#include <stdio.h>
int main() {
int years;
printf("Enter the number of years of employment service: ");
scanf("%d", &years);
if (years > 25) {
printf("You receive a gold watch\n");
} else if (years > 15 && years < 25) {
printf("You receive a silver pen\n");
} else if (years > 5 && years < 15) {
printf("You receive an attractive pin\n");
} else if (years >= 0 && years <= 5) {
printf("You receive a pat on the back\n");
}
return 0;
}
```
Note: In the code, we are using the logical operators (&&) for the conditions where multiple comparisons are required. The (&&) operator ensures that both conditions must be true for the corresponding code block to execute.
```
start
|
V
Ask user for number of years of employment service
|
V
Read user input and store it in a variable (years)
|
V
If years greater than 25
|
V
Display "You receive a gold watch"
|
V
Else if years greater than 15 AND years less than 25
|
V
Display "You receive a silver pen"
|
V
Else if years greater than 5 AND years less than 15
|
V
Display "You receive an attractive pin"
|
V
Else if years between 0 and 5
|
V
Display "You receive a pat on the back"
|
V
End
```
And here is the C code for the program:
```c
#include <stdio.h>
int main() {
int years;
printf("Enter the number of years of employment service: ");
scanf("%d", &years);
if (years > 25) {
printf("You receive a gold watch\n");
} else if (years > 15 && years < 25) {
printf("You receive a silver pen\n");
} else if (years > 5 && years < 15) {
printf("You receive an attractive pin\n");
} else if (years >= 0 && years <= 5) {
printf("You receive a pat on the back\n");
}
return 0;
}
```
Note: In the code, we are using the logical operators (&&) for the conditions where multiple comparisons are required. The (&&) operator ensures that both conditions must be true for the corresponding code block to execute.
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.