Question: for C# lab * Step 5 - Use a for loop to loop from 1-100. Each time through the loop, output the loop control variable

for C# lab

* Step 5 - Use a for loop to loop from 1-100. Each time through the loop, output the loop control variable and whether or not it is even or odd.

Here is code for checking to see if it's even or odd:

*/

int oddeven = 1;

// The condition (oddeven % 2 == 0) checks for even

// You just need to wrap a for loop around this if statement

if (oddeven % 2 == 0) {

Console.WriteLine($"{oddeven} is even.");

}

else {

Console.WriteLine($"{oddeven} is odd.");

}

/* Step 6 - Use a while loop. Allow a user to input a value.

Convert the input to an integer.

if the input = 0, end the loop. Otherwise, keep asking for input.

A team member gives you the following pseudocode:

- create int variable inputvar

- assign a value -1 to inputvar

- while (inputvar is not equal to 0)

- prompt user for input

- read input using Console.ReadLine()

- Convert it to an input using Convert.ToInt32()

- assign the value to inputvar

- output "You entered " + inputvar

*/

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!