Write a program using if-statements to print out the concert ticket price according to audience’s age. You must include a while loop so the program can execute three times for people with three different ages.
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
Write a program using if-statements to print out the concert ticket price according to audience’s age. You must include a while loop so the program can execute three times for people with three different ages.
- Your program should ask the user to enter age.
- Your program should determine using if-statements the price of the concert ticket based on the entered age.
- Your program should then print out the price of the ticket.
- Your program should use a while loop to repeat the mentioned process above three times.
The following are the ticket price range for different age group:
If a person is under 12 the price of the ticket is $10.
If the person is 65 or older the ticket price is $8.
If the person age is 12 or older but less than 65 the ticket price is $20.
Solution (pseudo-code)
set total to zero
set loop counter to 1
While loop counter is less than or equal to 3 do the following
Initialize total
enter age
if age< 12
print ticket price=$10
if age equal or > 65
print ticket price=$8
otherwise
print charge=$20
increment loop counter by one
END (after 3 times through the while loop)
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images