Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Republic of the Philippines

POLYTECHNIC UNIVERSITY OF THE PHILIPPINES


BIÑAN CAMPUS

Villanueva, Maria Yuki G. November 2022


BSIT 2-1 Ms. Indaleen

Instructions
Write a C# statement to accomplish each of the following:

1. Define variables timeIn, timeOut, and workedHrs

- In my perspective, timeIn is used when a user inputs the time that he or she arrived at work,
timeOut is used to define an endless waiting period or the end of the user's work, and workedHrs
is the sum of the user inputs and the waiting period or end of the user's work.

2. Prompt the user to enter a string. End your prompting message with a colon (:) followed by a space
and leave the cursor positioned after the space.

class Act1
{
static void Main()
{

Console.WriteLine("What’s Your Name?");

string name = Console.ReadLine();

Console.WriteLine("Hello, " + name + ":");

Console.ReadKey();
}
}
Republic of the Philippines
POLYTECHNIC UNIVERSITY OF THE PHILIPPINES
BIÑAN CAMPUS

3. Read a user input and store it in an integer variable.

class Act1
{
static void Main()
{
string value;
int number;

Console.WriteLine("Input an Integer: ");


value = Console.ReadLine();

number = Convert.ToInt32(value);

Console.WriteLine("Input = {0}", number);


}
}

4. If number is not greater than 18, print "User is a minor."

public class Act1


{
static void Main()
{
int age;

Console.Write("Input the age: ");


age = Convert.ToInt32(Console.ReadLine());
if (age < 18)
{
Console.Write("User is a Minor.\n");

}
else
Console.Write("User is Legal");
}
}
Republic of the Philippines
POLYTECHNIC UNIVERSITY OF THE PHILIPPINES
BIÑAN CAMPUS

5. Display the message "This is a C# program" with each word on a separate line.

class Act1
{
static void Main()
{
System.Console.WriteLine("This");
System.Console.WriteLine("is");
System.Console.WriteLine("a");
System.Console.WriteLine("C#");
System.Console.WriteLine("program");

}
}

You might also like