Intro to Programming Lab 7 – In C# Selected previous problems
For this lab you will use Visual Studio. I have created a Visual Studio Project for you to use. Unzip it and open with
Visual Studio. Use the Program.sc file for all problems. A method has been created for each problem. You will
create additional methods/functions as indicated in the question. Add a comment for your name at the top. You can
comment out the call to each problem method in main as you get them done. Leave them uncommented when you
turn it in. You will zip the entire project and upload the zip file on this assignment. Make sure your output
format matches the sample run output.
1) Write a program in Problem1 method that prompts the user for the amount of change (0 – 99) and calculates
the correct (fewest number of coins) number of quarters, dimes, nickels and pennies to return as change.
Hint: Be sure to use a whole number (int)type for all variables. Use Div (/ with int types) and Mod (%) operators.
Sample run:
Enter total change: 87
Quarters: 3
Dimes: 1
Nickels: 0
Pennies: 2
2) Write a program in Problem2 method that prompt for a whole number and print the correct statement based on
the following rules:
if the number is evenly divisible by 3 print Sassee
if the number is evenly divisible by 5 print Wazza
if the number is evenly divisible by 3 and 5 print SasseeWazza
if the number is not evenly divisible by 3 or 5 print the number
Sample run:
Enter a number: 30
SasseeWazza
3) Write a program in Problem3 method that plays the number guessing game. Ask the user for the number of
numbers, ie 10 for secret number between 1 and 10, 100 for secret number between 1 and 100. Use the Random
object to generate the secret number. Prompt the user for their guess, tell them to “Guess higher”, “Guess lower” or
“Correct after x guesses”.
Sample run (when secret is 3):
Enter number of numbers: 10
Guess: 5
Guess Lower
Guess: 2
Guess Higher
Guess: 3
Correct after 3 guesses
4) Write a program in Problem4 method that calculates the even and odd average of whole numbers input. The
user will enter “done” when complete. Use a real number type to calculate and store averages, not integer division.
Sample run:
Enter number: 11
Enter number: 24
Enter number: 18
Enter number: 29
Enter number: 7
10/14/2020 Assignment
https://helenacollege.mrooms.net/mod/assign/view.php?id=261476&forceview=1 2/4
Enter number: done
Even Average: 21
Odd Average: 15.6666666666667
5) Write a program in Problem 5 method that produces the printout below. Be sure to use dash “-” and asterisk
“”. Sample run: -------
------* -----
----* ---* --
-***
- --
---
----
-----** ------
-------*
6) Create a method GetIntArrayFromUser that takes the size of the array to retrieve from the user and prompts
the user for all values one at a time, then returns the array. Write a program in Problem6 method that uses the
GetIntArrayFromUser method to reads 6 numbers from the console and print the values in the array using a foreach
loop.
Sample run:
Enter next whole number: 9
Enter next whole number: 4
Enter next whole number: 17
Enter next whole number: 8
Enter next whole number: 21
Enter next whole number: 6
9
4
17
8
21
6
7) Create a method AverageIntArray that takes an array of integers and calculates and returns the average of all
values in the array as a double Write a program in Problem7 method that uses GetIntArrayFromUser method to get
an array of 7 numbers, then calls the AverageIntArray method to get the average then prints all values in the array
that are greater than the average.
Sample run:
Enter next whole number: 3
Enter next whole number: 8
Enter next whole number: 4
Enter next whole number: 12
10/14/2020 Assignment
https://helenacollege.mrooms.net/mod/assign/view.php?id=261476&forceview=1 3/4
Enter next whole number: 13
Enter next whole number: 6
Enter next whole number: 9
Average: 7.85714285714286
8
12
13
9
8) Create a method CountTargetIntArray that takes an array of integers and the target value then counts and
returns the number of times the target value appears in the array. Problem8 method that uses
GetIntArrayFromUser method to get an array of 10 numbers, then calls the CountTargetIntArray method to get the
count then prints the number of times the target was found in array.
Sample run:
Enter next whole number: 2
Enter next whole number: 6
Enter next whole number: 2
Enter next whole number: 4
Enter next whole number: 5
Enter next whole number: 2
Enter next whole number: 4
Enter next whole number: 3
Enter next whole number: 6
Enter next whole number: 2
Enter target value: 2
target found 4 times
9) Create a program in Problem9 that prompts the user for product price and quantity, and continues until the
user enters N when asked to continue. Store the inputs (price and quantity)in separate arrays. Once the user has
entered N, calculate the grand total, print the grand total, then print the item number as well as the subtotal for each
item. The quantity will always be a whole number. Use appropriate data types for the arrays. Assume the user will
never enter more than 10 products.
Sample run:
Add to order (Y/N): Y
Enter Price: 52.25
Enter Quantity: 4
Add to order (Y/N): Y
Enter Price: 21.85
Enter Quantity: 5
Add to order (Y/N): Y
Enter Price: 1.25
Enter Quantity: 55
Add to order (Y/N): N
Grand Total: $387.00
Item 1 subtotal: $209.00
Item 2 subtotal: $109.25
Item 3 subtotal: $68.75
10) Create a program in Problem10 that works just like problem 9 but is not limited to supporting only 10 products.
Do this by using a lists instead of arrays for the prices and quantities.
Sample run:
10/14/2020 Assignment
https://helenacollege.mrooms.net/mod/assign/view.php?id=261476&forceview=1 4/4
Add to order (Y/N): Y
Enter Price: 52.25
Enter Quantity: 4
Add to order (Y/N): Y
Enter Price: 21.85
Enter Quantity: 5
Add to order (Y/N): Y
Enter Price: 1.25
Enter Quantity: 55
Add to order (Y/N): N
Grand Total: $387.00
Item 1 subtotal: $209.00
Item 2 subtotal: $109.25
Item 3 subtotal: $68.75