Question: Write a program that asks the user how many numbers will be entered and then has the user enter those numbers. When this is done,
Write a program that asks the user how many numbers will be entered and then has the user enter those numbers. When this is done, report to the user the position of the first 7 entered and the last 7 entered. By position we mean, for example, that if the first 7 is the 2nd number entered then its position would be 2. Turn in the following 3 outputs exactly as you see them below to demonstrate that your program works in each case.
Don't forget to use a named constant for the "7".
Sample screen output 1:
How many numbers will be entered? 8 Enter num: 5 Enter num: 7 Enter num: 6 Enter num: 7 Enter num: 7 Enter num: 3 Enter num: 8 Enter num: 6 The first 7 was in position 2 The last 7 was in position 5
Sample screen output 2:
How many numbers will be entered? 8 Enter num: 5 Enter num: 2 Enter num: 6 Enter num: 7 Enter num: 1 Enter num: 3 Enter num: 8 Enter num: 6 The first 7 was in position 4 The last 7 was in position 4
Sample screen output 3:
How many numbers will be entered? 8 Enter num: 5 Enter num: 1 Enter num: 6 Enter num: 5 Enter num: 9 Enter num: 3 Enter num: 8 Enter num: 6 Sorry, no 7's were entered.
Hints: Everything you need to know to solve the problem is in the lessons. This is one of those problems that will challenge your problem solving skills. There's nothing hard about the C++ code here. What's hard is solving the underlying problem. One way to think about it would be to forget about computers for a moment, and figure out how you would solve this problem if you are the computer and a friend is the user. Suppose your friend gives you 1,000 numbers, and when she's done, you have to tell her which position the first 7 was in and which position the last 7 was in. Suppose you can't actually remember anything at all, so you have to write down whatever it is that you need to keep track of (this simulates using variables in a computer program). Ask yourself, what do you write down before you start? What do you do each time your friend says the next number? And you can't write down all of the numbers, you can only be keeping track of say 3 - 5 numbers at a time.
Another angle if this seems hard would be to instead pretend that you have two friends, one being the computer and one being the user. Your job is to watch your friend who is the computer and explain to her what she needs to do each time a new number is stated by your friend who is the user.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
