Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1 Convert the following loop into a for loop bool keepGoing = true; int count = 0 ; while ( keepGoing & & count

Question 1
Convert the following loop into a for loop
bool keepGoing = true;
int count =0;
while (keepGoing & & count 3)
{
Console.WriteLine(count);
Console.WriteLine("Keep going?");
keepGoing = Convert.ToBoolean(Console.ReadLine());
count++;
}
Question 2
The code in question 2 currently has no validation. Check for the following cases:
Non-numeric input
Negative number input
Number greater than 19,000,000 input
If any of the validation cases are encountered, output "error" to the user. Other deposit amount to the user.
Question 3
Convert the following if-else into a switch case:
Console.WriteLine("Enter a username");
string ulnput = Console.ReadLine();
if (ulnput == "admin")
Console.WriteLine("Nice try");
else if (ulnput == "user")
Console.WriteLine("Too common!");
else if (ulnput == "password")
Console.WriteLine("That comes later");
else
Console.WriteLine("Username set!");
Question 4
Write a program to simulate feeding ducks at a park.
Repeat the following commands until the user wants to stop feeding ducks or has fed 20 ducks:
Ask the user how many ducks they would like to feed
Display the number of ducks the user has fed
Ask the user if they would like to continue
If repetition stops because the user fed 20 ducks or more, display the message "you have been overwhelmed by ducks."
Question 5
Complete the method addingEvens()
The method has an integer return and two integer parameters
The method returns the sum of all even integer parameter values
A value is even if it is divisible by 2.
0 is considered an even number for this problem
If no parameters are even, the method returns-1
For example: addingEvens (2,4) returns 6, addingEvens (3,8) returns 8, addingEvens returns -1
Call the method from the main 3 times with the following arguments
Two even numbers
One even and one odd number
Two odd numbers
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions