using System;
using System.Collections.Generic;
using System.Text;
namespace Albores_Francis
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("------------------Problem 1------------------");
string a, b, c, d;
int sum, prod, diff, A, B, C, D;
float qout;
Console.Write("Enter integer 1: ");
a = Console.ReadLine();
Console.WriteLine("");
Console.Write("Enter integer 2: ");
b = Console.ReadLine();
Console.WriteLine("");
Console.Write("Enter integer 3: ");
c = Console.ReadLine();
Console.WriteLine("");
Console.Write("Enter integer 4: ");
d = Console.ReadLine();
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("");
A = Int32.Parse(a);
B = Int32.Parse(b);
C = Int32.Parse(c);
D = Int32.Parse(d);
sum = A + B + C + D;
prod = A * B * C * D;
diff = A - B;
qout = 1/2;
Console.WriteLine("Sum: " + sum);
Console.WriteLine("");
Console.WriteLine("Product: " + prod);
Console.WriteLine("");
Console.WriteLine("Difference (1 and 2): " + diff);
Console.WriteLine("");
Console.WriteLine("Quotient (3 and 4): " + qout);
Console.WriteLine("");
Console.WriteLine("------------------Problem 2------------------");
string numofStud_S, grade_S, persentPS, persentFS;
int numofStud, grade, passed = 0, failed = 0;
float persentP, persentF;
Console.Write("Enter number of students to process: ");
numofStud_S = Console.ReadLine();
numofStud = Int32.Parse(numofStud_S);
bool invalid = false;
for (int x = 0; x < numofStud; x++)
{
do
{
Console.Write("Enter grade for student {0} 60-100: ", x + 1);
grade_S = Console.ReadLine();
grade = Int32.Parse(grade_S);
if (grade <> 100)
{
Console.WriteLine("Error: Grade must be within 60 to 100");
invalid = true;
}
else
invalid = false;
} while (invalid == true);
if (grade >= 75 && grade <= 100)
passed++;
else
{
failed++;
}
}
persentPS = passed.ToString();
persentFS = failed.ToString();
Console.WriteLine("");
Console.WriteLine("Total no. of students: "+numofStud);
Console.WriteLine("No. of students who passed: " + passed);
Console.WriteLine("No. of students who failed: " + failed);
Console.WriteLine("");
persentP = (float.Parse(persentPS) / float.Parse(numofStud_S) * 100);
persentF = (float.Parse(persentFS)/float.Parse(numofStud_S)*100);
Console.WriteLine("Percentage of students who passed: "+persentP+"%");
Console.WriteLine("Percentage of students who failed: " + persentF + "%");
Console.ReadLine();
}
} }
Sunday, July 22, 2007
[Answer] Review Exercises # 1&2
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment