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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started