You are on page 1of 18

GUDITO, DESSA N.

BSME-MECH-2 METE280 - P1

WEEK 2A EXERCISES:
Basic Elements in C#
Problem 1: Write a program that accept an integer representing the total number of seconds
and output the equivalent time in hours, minutes, and seconds.
using System;

namespace Exercise1
{
class Program
{
static void Main(string[] args)
{
int hour, min, sec, input;

Console.Write("Input number of seconds: ");


input = Convert.ToInt32(Console.ReadLine());

hour = input / 3600;


min = (input % 3600) / 60;
sec = (input % 3600) % 60;

Console.WriteLine("\n{0} seconds is equivalent to:", input);


Console.WriteLine("\t{0} hours", hour);
Console.WriteLine("\t{0} minutes", min);
Console.Write("\t{0} seconds", sec);

Console.ReadLine();
}
}
}
Problem 2: Write a program that will solve the problem below: Chififay was promised by her
employer a 10% raise for the month. If her salary is P700 per month, how much will she receive
the next month if she gets cash advance of P500 and promise to pay it the next month?
using System;

namespace Exercise2a2_MonthlyPay
{
class Program
{
static void Main(string[] args)
{
int pay = 700;
double total = 0;

total = ((pay * 1.1) * 2) - 500;

Console.WriteLine("Salary next month = Php {0:0.00} ", total);

Console.ReadKey();
}
}
}
Problem 3: Write a program that extracts and prints the second rightmost digit of the integral
portion of a float.
using System;

namespace Exercise2a3_Second_Digit
{
class Program
{
static void Main(string[] args)
{
float num;
int place2;

Console.Write("Input a number with a decimal: ");


num = Convert.ToSingle(Console.ReadLine());

place2 = ((int)num / 10) % 10;

Console.WriteLine("\nThe second rightmost digit is {0}", place2);

Console.ReadKey();
}
}
}
WEEK 2B EXERCISES:
Conditional Control Structure
Problem 1:
A company selling household appliances gives commissions to its salesman determined by the
kind of product sold as well as the sales amount.
Type 1: 7% of sale or 400, whichever is more.
Type 2: 10% of sale or 900, whichever is less.
Type 3: 12% of sale.
Type 4: P250, regardless of sale price.
Make a program that would input the KIND of appliance sold (between 1-4) and the sale PRICE
(a positive floating-point value), and output the Commission that the salesman will receive.
using System;

namespace Exercise2b1_Commission
{
class Program
{
static void Main(string[] args)
{
int type;
double sale, com = 0, totalcom = 0;

Console.Write("Enter type of appliance sold (1-4): ");


type = Convert.ToInt32(Console.ReadLine());

Console.Write("Enter amount of sales: ");


sale = Convert.ToDouble(Console.ReadLine());

if (type == 1)
{
com = sale * 0.07;
if (com > 400)
{
totalcom = com;
}
else
{
totalcom = 400.00;
}
Console.WriteLine("\nTotal Commission is {0:0.00}", totalcom);
}
else if (type == 2)
{
com = sale * 0.1;
if (com < 900)
{
totalcom = com;
}
else
{
totalcom = 900.00;
}
Console.WriteLine("\nTotal Commission is {0:0.00}", totalcom);
}
else if (type == 3)
{
totalcom = sale * .12;
Console.WriteLine("\nTotal Commission is {0:0.00}", totalcom);
}
else if (type == 4)
{
totalcom = 250.00;
Console.WriteLine("\nTotal Commission is {0:0.00}", totalcom);
}
else
{
Console.WriteLine("Wrong input!");
}

Console.ReadKey();
}
}
}
Problem 2:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Exercise2b2_DeepQuest
{
class Program
{
static void Main(string[] args)
{
int region, timecode;
double min, totsec, sec, charge = 0, total = 0;

Console.WriteLine(" Region Code\t Region\t\tDay Time Rate\t\tNight Time


Rate");
Console.WriteLine("\t\t\t\t(Time code = 1)\t\t(Time code = 2)");
Console.WriteLine("\t1\tAsia\t\t18.74/min\t\t14.35/min");
Console.WriteLine("\t2\tAustralia\t21.36/min\t\t19.41/min");
Console.WriteLine("\t3\tAntarctica\t68.42/3mins\t\t65.25/3mins");
Console.WriteLine("\t4\tNorth America\t20.61/min\t\t18.23/min");
Console.WriteLine("\t5\tSouth America\t21.22/min\t\t20.13/min");
Console.WriteLine("\t6\tAfrica\t\t59.65/3mins\t\t57.32/3mins");
Console.WriteLine("\t7\tEurope\t\t87.38/4mins\t\t84.72/4mins");

Console.Write("\n\nInput region code: ");


region = Convert.ToInt32(Console.ReadLine());

Console.Write("Input time code: ");


timecode = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Input total call time:");


Console.Write("\tNo. of minutes: ");
min = Convert.ToDouble(Console.ReadLine());
Console.Write("\tNo. of seconds: ");
sec = Convert.ToDouble(Console.ReadLine());

totsec = ((double)sec / 60);


total = min + totsec;

if (timecode == 1)
{
switch (region)
{
case 1: charge = total * 18.74; break;
case 2: charge = total * 21.36; break;
case 3: charge = ((double)total / 3) * 68.42; break;
case 4: charge = total * 20.61; break;
case 5: charge = total * 21.22; break;
case 6: charge = ((double)total / 3) * 59.65; break;
case 7: charge = ((double)total / 4) * 87.38; break;
default: Console.WriteLine("Wrong region code input"); break;
}
}
else if (timecode == 2)
{
switch (region)
{
case 1: charge = total * 14.35; break;
case 2: charge = total * 19.41; break;
case 3: charge = ((double)total / 3) * 65.25; break;
case 4: charge = total * 18.23; break;
case 5: charge = total * 20.13; break;
case 6: charge = ((double)total / 3) * 57.32; break;
case 7: charge = ((double)total / 4) * 84.72; break;
default: Console.WriteLine("Wrong region code input"); break;
}
}
else
{
Console.WriteLine("\tWrong time code input");
}

Console.WriteLine("\n\n\tBased on your region and time code, the total charge


for the registered call is {0:0.00}", charge);
}
}
}

You might also like